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="data source=********;initial catalog=Twitter;user id=*********;password=********;MultipleActiveResultSets=True;App=EntityFramework"" 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]
}
}
}