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 を理解するのに 1 日を費やしてしまいました... それを袋に入れて、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>

私はまだ開発マシンにいるので、これは正しい接続文字列です。

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 : Entity Framework と ASP.NET メンバーシップに同じデータベースを使用する

サーバーから結果を受信中にトランスポート レベルのエラーが発生しました

于 2012-03-29T05:31:43.300 に答える