1

I have SQL Server 2008 R2 SP2 on my desktop with a database named "DB" on it (SQL Server and Windows authentication mode). I created a login/user to access the database without using the windows authentication (I know, it's bad, we'll discuss it after).

From my laptop, I have no problem accessing the database in visual studio through the server explorer, and I also managed to add in my solution a ADO.NET entity data model based on my database.

If i run the project from my desktop, everything works perfectly fine and fast (actually there is nothing to do except to read the db when the project is launched).

If i run it from my laptop, nothing happens for a minute or two, and then crash before showing anything. The exception appears on my MainWindow.xaml on the following line :

<trvws:TreeviewReg Margin="0,0,0,0" Height="Auto" Width="Auto" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />

Here is the error :

'The invocation of the constructor on type 'Twitter_NNA.Treeviews.TreeviewReg' that matches the specified binding constraints threw an exception.'

This line just opens a custom control with a treeview bound to the database.

In the IntelliTrace, I have other exceptions :

Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgment. This could be because the pre-login handshake failed or the server was unable to respond back in time. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=63057;handshake=2;

And

The underlying provider failed on open

Also, after I make attempts to run the project, there are an additional 2 errors that pops up:

The name "......." does not exist in the namespace "......"

The thing is that the name actually exist in the namespace and that those errors don't show up on the desktop.

So why the laptop can access the database from the "server explorer" window or by inserting items in the solution, but seems to be unable to do so at runtime? Can I force the # of connection attempt before giving up? Note: the whole thing is done over a wifi connection

If it can help, from the data model in my solution if on the diagram i try to update the model from database, i takes a while but manage to connect to the database to update.

I also have a subsidiary question: how can I create on my desktop the same user as on my laptop so I can use windows authentication? Or said other way, is there any good tutorial that can explain how to create windows user on a server that will be used by my network computer to connect (i tried some "user account & network" kind of query on Google, but found very generic thing on windows user accounts and nothing so specific).

[edit @James]

The database access code is automatically generated when inserting an ADO.NET Entity Data Model (= Entity Framework).

The connection string is :

<add name="TwitterEntities" connectionString="metadata=res://*/DataBase.TwitterDb.csdl|res://*/DataBase.TwitterDb.ssdl|res://*/DataBase.TwitterDb.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=********;initial catalog=Twitter;user id=*********;password=********;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

I have no reason to have doubts on the quality of the automatic code (which anyway works fine on the desktop). On my side of the code, the exception is thrown at the for each:

public void CountryConstructor()
    {

        //get the data from the query
        using (var TwitterDb = new TwitterEntities())
        {
                            //empty the current treeview
            AllRegions.Clear();

            //open the query and order it alphabetically
            foreach (var cTv in TwitterDb.CountryTreeviews
                                                .OrderBy(r => r.region_name)
                                                .ThenBy(c => c.country_name)
                                                .ThenBy(s => s.sector_name)
                                                .ThenBy(e => e.entity_name)
                                                .ToList())
            {
                   [Whatever here]
            }
        }
    }
samuel guedon
  • 575
  • 1
  • 7
  • 21
  • We would need to see the database access code. – James Jan 18 '15 at 05:55
  • 1
    For the second question, you need an Active Directory Server which manages an Active Directory Domain with each computer as a member of that domain and an Active Directory User with rights to the database. – James Jan 18 '15 at 05:57
  • See edit. For the 2nd question, I will keep on the SQL Server authentication :) – samuel guedon Jan 18 '15 at 11:01
  • I think you should add the `entity-framework` tag. I'm not familiar with that and I think that's more likely to be the cause than the compiler version you've tagged. It may also be an issue with the method being used to connect to the database (named pipe, tcp, etc.). I believe that SSMS will try several different methods--not sure about the way you're doing it. – James Jan 18 '15 at 15:35
  • Have you tried the IPV6 troubleshooting as per here: http://stackoverflow.com/questions/15488922/connection-to-sql-server-works-sometimes... also please delete your other question. – Nick.Mc Jan 29 '15 at 08:46
  • @Nick.McDermaid sorry for the very late answer, and yes I tried the IPV6 troubleshooting. Doing so I realized something, with all my IPs list there is also an IPAll group that just have TCP Dynamic Ports & TCP Port field. The Dynamic says it should be 0 for dynamic while I have a port specified. If I force 0 and save and restart the server, the 0 change to a new port number. Can it be that, or is it a normal behavior at the server start? – samuel guedon Feb 17 '15 at 22:49
  • I probably can't help much further but to be honest I won't anyway if you're going to double post: http://stackoverflow.com/questions/28182184/entity-framework-unable-to-connect-to-network-database – Nick.Mc Feb 17 '15 at 23:24
  • Feel free to do whatever you like. This post was dead (no answer, no matter that i changed the tags or anything). So I had the option to wait for an unlikely hypothetic revival of this thread or create a new one. I made my choice. And by the way I can't delete the other one now as someone flagged it as answered. Thanks for the help. – samuel guedon Feb 17 '15 at 23:34

1 Answers1

0

I found the solution by checking on the option offered in the "Advanced" part of the connection wizard. The Network Library (TCP/IP, Named Pipes, Shared Memory or VIA) can be forced, while it is blank by default (and I guess auto chosen to a wrong option).

I tried all of them, and only the "Named Pipes" worked for me.

The modification can be done manually in the connection string by adding

;network library=dbnmpntw

The connection string is now :

<add name="TwitterEntities" connectionString="metadata=res://*/DataBase.TwitterDb.csdl|res://*/DataBase.TwitterDb.ssdl|res://*/DataBase.TwitterDb.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=********;initial catalog=Twitter;user id=*********;password=********;network library=dbnmpntw;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
samuel guedon
  • 575
  • 1
  • 7
  • 21