VS连接SQLSERVER数据库的几种方式

来源:互联网 发布:税控系统开票软件 编辑:程序博客网 时间:2024/04/27 13:28

一、VS连接本地数据库(localdb)

<add name="TestSqlServer" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=Student;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\Student.mdf" />
注:其中TestSqlServer为数据库上下文类,默认为Defaultconnection,ConnectionString中的Data Source为本地数据库名称,可在视图SQLSERVER管理器中查看。Initial Catalog即为数据库名称,于后面的AttachDBFilename对应,DataDirectory即为数据库附加路径。

二、VS连接SqlServer(windows身份认证)

<add name="TestSqlServer" providerName="System.Data.SqlClient" connectionString="Data Source=127.0.0.1;Initial Catalog=TestUserInfo;Integrated Security=SSPI;" />

三、VS连接SqlServer(sa用户认证)

<add name="TestSqlSqever" providerName="System.Data.SqlClient" connectionString="Data Source=.;Database=TestUserInfo;Trusted_Connection=false;User ID=sa;Password=sa" />
原创粉丝点击