方法一:
Windows验证登录:
sqlconnection.ConnectionString =
"Server=(local);DataBase=EduBaseHos;Integrated Security=sspi";
方法二:
sqlconnection.ConnectionString = "Server=(local);DataBase=EduBaseHos;uid=jsj;[email protected]";
方法三:当SQL的服务器为:本机名称\SQLEXPRESS,用以上两个方法连接时,均会出现连接错误。因而应采用以下方法:
String connection =
@"Data Source=.\sqlexpress;Initial Catalog=EduBase2018;Integrated Security=sspi";
SqlConnection sqlConnection = new SqlConnection(connection);