当我尝试使用ADO.NET建立与SQL Server的连接时,它显示错误。ADO.NET连接结果实例失败
这是我的代码使用方法:
SqlConnection con = new SqlConnection(@"Data Source=.\\SQLEXPRESS;Initial Catalog=abdul;uid=sa;pwd=sqlserver");
SqlCommand cmd = new SqlCommand();
con.Open();
String str="select * from emp where empname='Abdul'";
cmd = new SqlCommand(str, con);
SqlDataReader dr = cmd.ExecuteReader();
if (dr == null || !dr.HasRows)
{
MessageBox.Show("No Records found");
}
else
{
while (dr.Read())
{
textBox1.Text = dr[0].ToString();
textBox2.Text = dr[1].ToString();
}
}
当我运行项目它显示了以下错误:
Instance failure.
我有什么做的?
您可以复制错误堆栈跟踪吗? –
@Alberto Leon:以下是系统上System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo,SqlInternalConnectionTds connHandler,Boolean ignoreSniOpenTimeout,Int64 timerExpire,布尔加密,Boolean trustServerCert,布尔integratedSecurity,SqlConnection拥有对象)的错误堆栈跟踪 。 Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo,String newPassword,Boolean ignoreSniOpenTimeout,Int64 timerExpire,SqlConnection owningObject) at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String这是不够的,把所有 –
为什么你不使用ConnectionStringBuilder for this:SqlConnection(@“Data Source =。\\ SQLEXPRESS; Initial Catalog = abdul; uid = sa; pwd = sqlserver”);? –