首先,我对LINQ to SQL很新,所以这可能是一个愚蠢的问题,但我试图在数据库中插入一条新记录,并且我不断收到以下错误:
The client was unable to establish a connection because of an error during connection initialization process before login. Possible causes include the following: the client tried to connect to an unsupported version of SQL Server; the server was too busy to accept new connections; or there was a resource limitation (insufficient memory or maximum allowed connections) on the server. (provider: Shared Memory Provider, error: 0 - The handle is invalid.)
我可以单步执行我的代码,看到所有数据都按照我的预期存在,但是当它到达时
db.SubmitChanges()
在下面的方法中我得到了错误。我究竟做错了什么?这太令人沮丧了,我已经失去了一天试图弄清楚LINQ to SQL ...我只想把它包起来然后回到使用ADO.NET和存储过程。
public static void Save(Customer customerToSave)
{
IpmDatabaseDataContext db = new IpmDatabaseDataContext();
db.Customers.InsertOnSubmit(customerToSave);
// commit the changes to the db
db.SubmitChanges();
}
在我的app.config中,它有这个连接字符串:
<connectionStrings>
<add name="IPM.Business.Properties.Settings.IPMConnectionString"
connectionString="Data Source=socrates\sqlexpress;Initial Catalog=IPM;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
我仍然在我的开发机器上,所以这是正确的连接字符串。
答案 0 :(得分:0)
您传递给IpmDatabaseDataContext
的连接字符串是什么?您获得的错误与LINQtoSQL无关,这是数据库连接问题。
要调试此问题,请尝试将连接字符串显式传递给DataContext
构造函数,例如:
IpmDatabaseDataContext db = new IpmDatabaseDataContext(
@"Data Source=localhost\SQLEXPRESS;Integrated Security=true");
以下帖子表明共享内存提供程序...句柄无效错误将在重新启动 Windows时消失:
ASP.NET MVC : Using the same database for Entity Framework and ASP.NET Membership
A transport-level error has occurred when receiving results from the server