I had the same issue and found that , its not possible to to run the soultion (which is developed in .Net 3.5 and SQL server 2005) in VS 2008 and Vs 2010, because VS 2010 installs SQL server 2008 instance and updated the SQL server 2005 instance to SQL
server 2008 instance if it is already installed, so now we lost SQL server 2005 instance.
We can run the solution in VS 2008 but can not deploy the DataBase project as it is trying to use SQL server 2008 instance.
We can run the solution in VS 2010 but can not deploy the Datebase project as it is using SQL server 2008 instance.
We are going crazy here...
we want to run the solution in VS 2008 and VS2010 (for test automation).
My issue is similar, but I am connecting to the 'live' SQL Server database on the remote server. I could connect to the db from everyting except when running from localhost using Visual Studio.
The site is working, so I know the connection string and connection is working.
From my development machine, I can connect via VS2008 Server Explorer as well SQL Server Management Studio.
Allow remote connections is enabled - double checked using SQL Server Management Studio.
My connection string looked like this:
<add name="MY_DB" connectionString="Data Source=DB_SRV_123; User Id=myuserid; Password=my_pwd; Initial Catalog=my_db; providerName="System.Data.SqlClient"/>
Note that the data source is referring to a machine name that is not known on my network. It's the live database! (This is when I stopped hitting my head on the wall)
Changing the connection string on my dev machine to the following allows the db server name to be resolved correctly from my dev environment.
<add name="MY_DB" connectionString="Data Source=DB_SRV_123.somedomain.com; User Id=myuserid; Password=my_pwd; Initial Catalog=my_db; providerName="System.Data.SqlClient"/>
Hopefully this may help out someone else who is having a problem or two...
I am having the same issue. Everything works on the development machine. The sql server is hosted so I should not have any issues with port opening. It worked this morning but now it give me this connection error. I have read a lot and have not found
the solution. Anymore suggestions?
FYI: Having the same issues with VB2008 Express and SQL 2008 Express R2. Your solution worked perfectly. Saved me hours of beating my head against my monitor. Sincere Thanks!
Well I think I used a simple trick and found the solution. I encountered this problem while making a simple ADO.Net based application. While in application, I tested my connection with this code.
In my project I added a Windows Form then dragged a button to it. Right click on button and went to source code and wrote this code in click event of button
FYI : My pc name was "Harshit-PC" which i selected as data source.
athelli_redd...
Member
8 Points
57 Posts
Re: A network-related or instance-specific error occurred while establishing a connection to SQL ...
Mar 23, 2010 06:06 AM|LINK
I had the same issue and found that , its not possible to to run the soultion (which is developed in .Net 3.5 and SQL server 2005) in VS 2008 and Vs 2010, because VS 2010 installs SQL server 2008 instance and updated the SQL server 2005 instance to SQL server 2008 instance if it is already installed, so now we lost SQL server 2005 instance.
We can run the solution in VS 2008 but can not deploy the DataBase project as it is trying to use SQL server 2008 instance.
We can run the solution in VS 2010 but can not deploy the Datebase project as it is using SQL server 2008 instance.
We are going crazy here...
we want to run the solution in VS 2008 and VS2010 (for test automation).
is my finding correct that it is not possible?
If it is possible, how?
Regards
Rajender
Avanade
NBstrat
Member
2 Points
1 Post
Re: A network-related or instance-specific error occurred while establishing a connection to SQL ...
Mar 27, 2010 02:06 AM|LINK
My issue is similar, but I am connecting to the 'live' SQL Server database on the remote server. I could connect to the db from everyting except when running from localhost using Visual Studio.
My connection string looked like this:
<add name="MY_DB" connectionString="Data Source=DB_SRV_123; User Id=myuserid; Password=my_pwd; Initial Catalog=my_db; providerName="System.Data.SqlClient"/>
Note that the data source is referring to a machine name that is not known on my network. It's the live database! (This is when I stopped hitting my head on the wall)
Changing the connection string on my dev machine to the following allows the db server name to be resolved correctly from my dev environment.
<add name="MY_DB" connectionString="Data Source=DB_SRV_123.somedomain.com; User Id=myuserid; Password=my_pwd; Initial Catalog=my_db; providerName="System.Data.SqlClient"/>
Hopefully this may help out someone else who is having a problem or two...
jeffclark72
Member
2 Points
1 Post
Re: A network-related or instance-specific error occurred while establishing a connection to SQL ...
May 11, 2010 04:14 AM|LINK
I am having the same issue. Everything works on the development machine. The sql server is hosted so I should not have any issues with port opening. It worked this morning but now it give me this connection error. I have read a lot and have not found the solution. Anymore suggestions?
lquarles
Member
2 Points
1 Post
Re: A network-related or instance-specific error occurred while establishing a connection to SQL ...
May 25, 2010 05:17 PM|LINK
FYI: Having the same issues with VB2008 Express and SQL 2008 Express R2. Your solution worked perfectly. Saved me hours of beating my head against my monitor. Sincere Thanks!
Harshit_Pand...
Member
4 Points
5 Posts
Re: A network-related or instance-specific error occurred while establishing a connection to SQL ...
Jun 14, 2010 07:54 AM|LINK
Well I think I used a simple trick and found the solution. I encountered this problem while making a simple ADO.Net based application. While in application, I tested my connection with this code.
In my project I added a Windows Form then dragged a button to it. Right click on button and went to source code and wrote this code in click event of button
FYI : My pc name was "Harshit-PC" which i selected as data source.
private void button1_Click(object sender, EventArgs e) { SqlConnection cs = new SqlConnection("Data Source=Harshit-PC; Initial Catalog=Youtube; Integrated Security=True"); cs.Open(); MessageBox.Show(cs.State.ToString()); cs.Close(); } }Here is the trick : I change the string for the path like this way
private void button1_Click(object sender, EventArgs e) { SqlConnection cs = new SqlConnection(@"Data Source=.\SQLEXPRESS; Initial Catalog=Youtube; Integrated Security=True"); cs.Open(); MessageBox.Show(cs.State.ToString()); cs.Close(); } }Bingo : it worked for me
But for all other guys check this link, which can be useful if the issue is yet not resolved.
1. http://www.mydigitallife.info/2007/10/31/error-has-occurred-while-establishing-a-connection-to-sql-server-2005-which-does-not-allow-local-and-remote-connections/
2. http://blogs.msdn.com/b/sql_protocols/archive/2007/03/31/named-pipes-provider-error-40-could-not-open-a-connection-to-sql-server.aspx
3. http://blog.sqlauthority.com/2007/04/23/sql-server-fix-error-40-could-not-open-a-connection-to-sql-server/
SQL Error Error 40