could not open a connection to sql server
I am using sql server 2005 and asp.net 2.0 in my home.
I established connection in my application and put code in page load
protected void Page_Load(object sender, EventArgs e)
{
string constring = "server=.\\SQLEXPRESS;uid=sa;pwd=;data source=dbAshok";
//Open the connection
sqlconnection = new SqlConnection(constring);
sqlconnection.Open();
string strquery = "select *from Employee";
dataset = new DataSet(strquery);
sqlconnection.Close();
}
But i got an error in open the connection. My error is below.
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
I couldn't fix this bugs. Please suggest me.
Hope yours reply.
Thanks
Re: could not open a connection to sql server
Hey,
So the first thing that I would suggest is that you put your connection string into the web.config file of your application. This will make things much easier going forward, as you will be able to modify it without having to re-compile your application.
Once you have done that, verify that you have got the correct connection string by looking here:
http://www.connectionstrings.com/sql-server-2005
Do you have SQL Server Management Studio? If so, can you connect through that to your database using the same credentials as you are trying here?
Gary
Re: could not open a connection to sql server
first, it's not a good idea to use the SA/no password for the login.... might want to change that ASAP.
Secondly, is the connection string correct? You are attempting to connect to the SQLExpress instance of the local server. Is SQL Express installed, or a full SQL Server? And is it on the same server as the web server?
-tg
Re: could not open a connection to sql server
Re: could not open a connection to sql server
Dear guys,
Thanks for your reply. I got it as what you told.
Thanks again.
Re: could not open a connection to sql server
Hey,
So that other people can benefit from your experience, can you explain exactly what you had to change to make it work?
Also, can you remember to go back and mark your thread as resolved?
Gary