1

First, I'm pretty new to LINQ to SQL, so this is probably a dumb question, but I'm trying to insert a new record into the database and I keep getting the following error:

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.)

I can step through my code and see that all the data is present as I would expect it to, but when it hits the

db.SubmitChanges()

in the method below I get the error. What am I doing wrong? This is SOO frustrating and I've lost a day trying to figure out LINQ to SQL... I'm half tempted to just bag it and go back to using ADO.NET and stored procs.

public static void Save(Customer customerToSave)
    {
        IpmDatabaseDataContext db = new IpmDatabaseDataContext();
        db.Customers.InsertOnSubmit(customerToSave);

        // commit the changes to the db
        db.SubmitChanges();     
    }

In my app.config it has this connection string:

<connectionStrings>
    <add name="IPM.Business.Properties.Settings.IPMConnectionString"
        connectionString="Data Source=socrates\sqlexpress;Initial Catalog=IPM;Integrated Security=True"
        providerName="System.Data.SqlClient" />
</connectionStrings>

I am still on my dev machine, so this is the correct connection string.

Cory
  • 658
  • 3
  • 7
  • 19
  • 1
    This probably has something to do with the Database setup or connection string (connection pooling, and such). Could you post some more info about that? – Rody Mar 29 '12 at 05:30
  • Your LINQ is probably OK. Check database connection (or rebuild the context) – Dmitry Reznik Mar 29 '12 at 05:31

1 Answers1

0

What is the connection string you are passing to IpmDatabaseDataContext? The error you are getting isn't related to LINQtoSQL, it's a database connectivity problem.

To debug the problem, try explicitly passing your connection string to the DataContext constructor, e.g.:

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

The following posts suggest that the Shared Memory Provider ... handle is invalid error will go away if you reboot 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

Community
  • 1
  • 1
Justin M. Keyes
  • 6,679
  • 3
  • 33
  • 60
  • In my app.config it has this connection string: – Cory Mar 29 '12 at 05:36
  • I just tried it and it didn't work. I got the same error. IpmDatabaseDataContext db = new IpmDatabaseDataContext(@"server=socrates\SQLEXPRESS;Integrated Security=SSPI;Database=IPM"); – Cory Mar 29 '12 at 05:43
  • Do you get the same "Shared Memory Provider ... handle is invalid" error when doing a normal ADO (non-LINQtoSQL) INSERT on the same table, same database, in the same project? – Justin M. Keyes Mar 29 '12 at 05:45
  • explicitly passing your connection string should work.if not plz check your connection string again. – chamara Mar 29 '12 at 06:27