当前位置:首页 > C#

sqlServer数据库常用连接字符串

happyfhb5年前 (2021-10-07)C#2195
摘要:

用户名和密码验证的方式去连接到数据库服务器

  <add name="conStr" connectionString="Data Source=服务器名;Initial Catalog=数据库名; User Id=用户名;Password=密码"/>  

  <add name="conStr" connectionString="Server=服务器名;Database=数据库名;User Id=用户名;Password=密码"/>  

<add name="conStr" connectionString="server=l服务器名;database=数据库名;uid=用户名;pwd=密码;pooling=true;min pool size=1;max pool size=2;connection reset=true"/>

 

Windows验证的方式去连接到数据库服务器

 

   <add name="conStr" connectionString="Data Source=服务器名;Initial Catalog=数据库名;Integrated Security=True;" />

    <add name="conStr" connectionString="Data Source=服务器名;Initial Catalog=数据库名;Integrated Security=SSPI;" />    

   <add name="conStr" connectionString="Data Source=服务器名;Initial Catalog=数据库名;Trusted_Connection = False;Encrypt = yes" />

<add name="conStr" connectionString=" data source=服务器名;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"/>

 

 

常用的属性:

服务器

Data Source

Server

数据库

Initial Catalog

database

用户名

User Id

uid

密码

Password

pwd

启用连接池

pooling=true(默认值)

最小连接数量

min pool size=1;

最大连接数量

max pool size=2

重置连接池

connection reset=true

身份验证方式

Integrated Security 
当为false时,将在连接中指定用户ID和密码。
当为true时,将使用当前的Windows帐户凭据进行身份验证。
可识别的值为true、false、yes、no以及与true等效的sspi。

信任连接

1)web.config中Trusted_Connection=true改为Trusted_Connection=false可以消除如下错误:
"用户
'NT AUTHORITY\NETWORK SERVICE' 登录失败。"
(2)Trusted_Connection

当为 false 时,将在连接中指定用户 ID 和密码。当为 true 时,将使用当前的 Windows 帐户凭据进行身份验证。 
可识别的值为 true、false、yes、no 以及与 true 等效的 sspi(强烈推荐)。

(3)当在WEB.CONFIG使用Trusted_Connection=true时,SERVER DATABASE已设置为用信任连接了.

加密

Encrypt = yes


扫描二维码推送至手机访问。

版权声明:本文由海海日记-冯海滨博客发布,如需转载请注明出处。

本文链接:http://www.fenghaibin.com/?id=1338

“sqlServer数据库常用连接字符串” 的相关文章

IIS_WPG用户组

IIS_WPG用户组在安装asp.net web应用程序时,发现文件夹的用户权限总设置不对,结果导致读写access数据库文件出错。仔细研究了一下,发现必须要给IIS_WPG用户组足够的权限,程序才能正常运行。IIS_WPG用户组是做什么的?为了管理的方便,在安装 IIS 6 时创建了 IIS_WP…

c#无返回值函数如何调用

 无返回值函数如何调用 事例 定义一个不需要返回值的函数 none()         static void none()//定义一个不需要返回值的函数        {&nbs…

C# windows服务程序中的Timer控件的添加方法

C# windows服务程序中的Timer控件的添加方法

开"工具箱"---右键---"选择项"---找到Timer控件,看好了,这个Timer控件的是system.Timer下的. 可不是System.Windows.Form.然后添加. …

Windows服务程序的编写、调试、部署

Windows服务程序的编写、调试、部署

L 基本概念什么是Windows服务?作为.net开发人员,平常写的都是winform程序或者asp.net程序,可能对Windows服务程序接触的不多,下面我摘了个百度文献的解释给大家:Microsoft Windows 服务(即以前的NT服务)使您能够创建在它们自己…

C#如何检测指定的Windows服务是否启动

C#如何检测指定的Windows服务是否启动

 在项目中,特别是安装项目中我们经常要判断一些服务是否启动(判断SQL Server是否启动最常见),在.net中我们如何判断指定的Windows服务是否启动呢?首先要知道Windows服务的显示名称,这里以IIS检测为例,我们知道IIS的显示名称是"IIS Admin"…

Sql server管理工具SQLManagementStudio2008的安装

Sql server管理工具SQLManagementStudio2008的安装

Sql server管理工具SQLManagementStudio2008一款功能强大的Sql server管理工具,下面就为您介绍该Sql server管理工具的安装方法,供您参考。果你用的是Visual Studio 2010, 那么需要自行安装SQLManagementStudio. 微软官方…

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。