need help asap? sqlexception was unhandled

liunx

Guest
the error show as below:
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections.

my code in my program is

private void viewAllAccount_Click_1(object sender, EventArgs e)
{
//connect to SQL Server
SqlConnection con = new SqlConnection("Server=LASHIOTHAR;Database=master;UID=;PWD=;");

con.Open();

SqlDataAdapter ad = new SqlDataAdapter("Select * From myAccount", con);

DataSet ds = new DataSet();
ad.Fill(ds, "myAccount");

dataGridView1.DataSource = ds.Tables[0].DefaultView;

con.Close();
}

pls help me how can i connect to microsoft sql server 2005.
i used microsoft server management studio express 2005 and connect to the server using window Authentication.

Please if my post is not in the right place , please show me and advise me.
thanksThere's no point posting all that code, when the exception is being raised by this line:


SqlConnection con = new SqlConnection("Server=LASHIOTHAR;Database=master;UID=;PWD=;");


I'm not sure what development environment you use. But your connection string is wrong. I tend to rip a connectionString from Web.config that has been auto-generated. Make life easy ; )No its occuring in the open statement. Likely caused by incorrect name of machine or unable to access SQL server.
 
Back
Top