当前位置:首页 > C#

sqlServer数据库常用连接字符串

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

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

  <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数据库常用连接字符串” 的相关文章

vb.net 随机函数 random 用法

VB.net 的写法dim rand as new random()i=rand.next(1,100)表示伪随机数生成器,一种能够产生满足某些随机性统计要求的数字序列的设备。命名空间:System程序集:mscorlib(在 mscorlib.dll 中)伪随机数是以相同的概率从一组有限的数字中选…

vb.net 多线程写法

注意 只能调用 不带参数的 sub 如果调用不同类的sub需要定义调用的sub是shared 是共享的 才可以的。相关语法Imports SystemImports System.Threading  '导入系统进程 Public Class Form1 &n…

IIS_WPG用户组

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

asp.net substring截取函数详细用法

asp.net  substring截取函数详细用法字符串截取,substring(int beginIndex) 返回一个新的字符串,它是此字符串的一个子字符串。substring(int beginIndex, int endIndex)  返回一个新字符串,它是此字符串的一…

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

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

c#中如何判断用户输入的字符全部为数字的方法-经典

             string num = textBox1.Text; //从文本框获取用户输入的值     …

发表评论

访客

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