常用的连接字符串(vs中连接sqlserver)方便随时查看

Sql Server身份验证有两种,一种是Windows身份验证,还有一种是Sql Server 身份验证

Windows身份验证连接字符串:

 string connectionString =
                "Data Source=localhost;database=数据库名称;Integrated Security=True;User Instance=False;";

Integrated Security 指的是集成安全性,为true,就是使用集成安全,后面User Instance 指的是用户实例,这里为False,不使用用户实例,这样方便不同用户使用,这也是本人比较常用的连接字符串。关于User Instance 详细内容参照下面链接,很详细

http://zhidao.baidu.com/link?url=c7dA0eVo7gby23pocNSLFoWSJHGElFNJltC9VZ2uKC6Ma42KNl1k8vsl4PABGihHb56_62KUlOYEHiZCGss-GX3jMaWRm19qzdpHMnVEhBy

Sql Server 身份验证连接字符串:

 string connectionString = @"server=服务器名;database=数据库名称;uid=用户名;pwd=密码";

当然我写的这个比较简单

更详细的参照:

http://www.cnblogs.com/tough/archive/2011/11/18/2254076.html

这些连接字符串一般写在配置文件里

右边项目添加新建项找到应用程序配置文件点击添加即可

在App.config中添加如下代码

 <appSettings>
    <add key="connectionString" value="你要连接的字符串"/>
  </appSettings>

然后在项目中就可以这样使用

string conStr = System.Configuration.ConfigurationManager.AppSettings.Get("connectionString");

 web中windows验证连接字符串

<add name="Accounting" providerName="System.Data.SqlClient" connectionString="Data Source=(local);Initial Catalog=Accounting;Integrated Security=SSPI;"/>
原文地址:https://www.cnblogs.com/jixinyu/p/4298505.html