1

首先,我对 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...

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>

我仍在我的开发机器上,所以这是正确的连接字符串。

4

1 回答 1

0

您传递给的连接字符串是IpmDatabaseDataContext什么?您收到的错误与 LINQtoSQL 无关,它是数据库连接问题。

要调试问题,请尝试将连接字符串显式传递给DataContext构造函数,例如:

IpmDatabaseDataContext db = new IpmDatabaseDataContext(
    @"Data Source=localhost\SQLEXPRESS;Integrated Security=true");

以下帖子表明,如果您重新启动Windows , Shared Memory Provider ... handle is invalid错误将消失:

ASP.NET MVC:对实体框架和 ASP.NET 成员使用相同的数据库

从服务器接收结果时发生传输级错误

于 2012-03-29T05:31:43.300 回答