1. 用SqlConnection 连接SQLServer数据库
try
{
string sqlConn = "server=DELL-PC/SQLEXPRESS1;database=OPGWDB;uid=sa;pwd=sa";
SqlConnection conn = new SqlConnection(sqlConn);
conn.Open();
DataTable dt = new DataTable();
string sql = "Select * from dbo.Yhjsb";
SqlDataAdapter ad = new SqlDataAdapter(sql, conn);
ad.Fill(dt);
conn.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
2. 但是一直报如下错误
3. 确保客户端登录没问题
4. 然后string sqlConn = @"server=DELL-PC\SQLEXPRESS1;database=OPGWDB;uid=sa;pwd=sa"; 问题解决
请发表评论