[RESOLVED] still can't connect to sql server
I get this error message:
A connection was successfully established with the server, but then an error occurred during the login process. (provider: TCP Provider, error: 0 - The specified network name is no longer available.)
This occurs when I try to open connection. Here is code:
Code:
string conStr = "Server=www.freesqlserver.com;Database=mytable;UID=john1;PWD=pass1;";//not actual user-pass
System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(conStr);
System.Data.SqlClient.SqlCommand cmd;
cmd = new System.Data.SqlClient.SqlCommand("Select * from mytable", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
note: There is no database created yet in this server.
Re: still can't connect to sql server
Quote:
Originally Posted by benmartin101
I get this error message:
A connection was successfully established with the server, but then an error occurred during the login process. (provider: TCP Provider, error: 0 - The specified network name is no longer available.)
This occurs when I try to open connection. Here is code:
Code:
string conStr = "Server=www.freesqlserver.com;Database=mytable;UID=john1;PWD=pass1;";//not actual user-pass
System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(conStr);
System.Data.SqlClient.SqlCommand cmd;
cmd = new System.Data.SqlClient.SqlCommand("Select * from mytable", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
note: There is no database created yet in this server.
what table are you connecting to?
and make sure that the user has a privelege to access the database you are connecting to
Re: still can't connect to sql server
You can't connect to a database that does not exist.
When you login to sql server you connect to the Master database (unless a default is assigned to the login). If you specify a database in the connection string, the login process will attempt to switch you to that database.
Re: still can't connect to sql server
Thanks. It's working now.