Hi I am trying to write the following connection string:
public static SqlConnection connect()
{
SqlConnection sqlConn = new SqlConnection("server=9.0.3042;database=Menu;Connection Lifetime=300");
return sqlConn;
}
I am trying to connect to a sql database using c# code. The code above is in a seperate file.
The code below is the code used to talk to the database
SqlConnection sqlConn = connection.connect();
sqlConn.Open();
SqlCommand menubar = new SqlCommand("Select * from Menu_table", sqlConn);
SqlDataAdapter dataAdapter5 = new SqlDataAdapter();
dataAdapter5.SelectCommand = menubar;
DataSet dataSet5 = new DataSet();
dataAdapter5.Fill(dataSet5);
DataTable selcartest4 = dataSet5.Tables["table"];
However the connection is just timing out like I have the wrong address set for the connection on the first bit of code posted
any heklp would be great
cheers
J
you have to give the NAME of the server not the version for the Server attribute. also you should specify the type of authentication. Referhttp://www.connectionstrings.com/?carrier=sqlserver2005 for some samples..
server=<ServerName>;database=Menu;Connection Lifetime=300
|||Hi
Thanks for the reply, I have changed the server name to its correct IP address but its stilf ailing and I get the followin g message:
The user is not associated with a trusted SQL Server connection.
I have set it in sql server for both sql and windows authentication
is there any reason for this to happen?
cheers
Jamie
If its not a production server, try restarting the SQL server and see if it helps.
|||Hi
I have tried re-starting it as its not a production server but still failing, is there something wrong with the firewall settings maybe.
Wehn I use the stadard connection string vwd provides its OK but I wanted to set up a connection string in c#
cheers
Jamie
No comments:
Post a Comment