第十六部分SQL连接的三种方式

方法一:

Windows验证登录:

sqlconnection.ConnectionString =

     "Server=(local);DataBase=EduBaseHos;Integrated Security=sspi";

方法二:

 sqlconnection.ConnectionString =                    "Server=(local);DataBase=EduBaseHos;uid=jsj;pwd=2wsx@WSX";

方法三:当SQL的服务器为:本机名称\SQLEXPRESS,用以上两个方法连接时,均会出现连接错误。因而应采用以下方法:

String connection =

@"Data Source=.\sqlexpress;Initial Catalog=EduBase2018;Integrated Security=sspi";

SqlConnection sqlConnection = new SqlConnection(connection);

posted @ 2018-01-16 13:13  奔跑吧菜鸟  阅读(193)  评论(0编辑  收藏  举报