SQL 常用连接字符串
2007-12-23 09:36
176 查看
SQL 常用连接字符串
Standard Security:
使用 SQL Server 身份验证:
"Data Source=Aron1;Initial Catalog=pubs;User Id=sa;Password=asdasd;"
- or -
"Server=Aron1;Database=pubs;User ID=sa;Password=asdasd;Trusted_Connection=False"
Trusted Connection:
使用 Windows 身份验证(信任连接):
"Data Source=Aron1;Initial Catalog=pubs;Integrated Security=SSPI;"
- or -
"Server=Aron1;Database=pubs;Trusted_Connection=True;"
Connect via an IP address:
"Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=pubs;User ID=sa;Password=asdasd;"
Enabling MARS (multiple active result sets):
仅仅支持 ADO.NET2.0
"Server=Aron1;Database=pubs;Trusted_Connection=True;MultipleActiveResultSets=true"
Note! Use ADO.NET 2.0 for MARS functionality. MARS is not supported in ADO.NET 1.0 nor ADO.NET 1.1
Streamline your Data Connections by Moving to MARS, by Laurence Moroney, DevX.com >>
Attach a database file on connect to a local SQL Server Express instance:
"Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf;Database=dbname;Trusted_Connection=Yes;"
- or -
"Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;Database=dbname;Trusted_Connection=Yes;"
(use |DataDirectory| when your database file resides in the data directory)
Why is the "Database" parameter needed? Answer: If the database was previously attached, SQL Server does not reattach it (it uses the attached database as the default for the connection).
Using "User Instance" on a local SQL Server Express instance:
"Data Source=.\SQLExpress;integrated security=true;attachdbfilename=|DataDirectory|\mydb.mdf;user instance=true;"
The "User Instance" functionality creates a new SQL Server instance on the fly during connect. This works only on a local SQL Server 2005 instance and only when connecting using windows authentication over local named pipes. The purpose is to be able to create a full rights SQL Server instance to a user with limited administrative rights on the computer. To enable the functionality: sp_configure 'user instances enabled','1' (0 to disable)
Using SQL Server 2005 Express? Don't miss the server name syntax: SERVERNAME\SQLEXPRESS (Substitute "SERVERNAME" with the name of the computer)
如果要进行同步/异步访问需要在字符串后面继续添加 Asynchronous Processing=true 默认关闭
如果要开启 MARS 则加上 MultipleActiveResultSets=True 默认开启。
Standard Security:
使用 SQL Server 身份验证:
"Data Source=Aron1;Initial Catalog=pubs;User Id=sa;Password=asdasd;"
- or -
"Server=Aron1;Database=pubs;User ID=sa;Password=asdasd;Trusted_Connection=False"
Trusted Connection:
使用 Windows 身份验证(信任连接):
"Data Source=Aron1;Initial Catalog=pubs;Integrated Security=SSPI;"
- or -
"Server=Aron1;Database=pubs;Trusted_Connection=True;"
Connect via an IP address:
"Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=pubs;User ID=sa;Password=asdasd;"
Enabling MARS (multiple active result sets):
仅仅支持 ADO.NET2.0
"Server=Aron1;Database=pubs;Trusted_Connection=True;MultipleActiveResultSets=true"
Note! Use ADO.NET 2.0 for MARS functionality. MARS is not supported in ADO.NET 1.0 nor ADO.NET 1.1
Streamline your Data Connections by Moving to MARS, by Laurence Moroney, DevX.com >>
Attach a database file on connect to a local SQL Server Express instance:
"Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf;Database=dbname;Trusted_Connection=Yes;"
- or -
"Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;Database=dbname;Trusted_Connection=Yes;"
(use |DataDirectory| when your database file resides in the data directory)
Why is the "Database" parameter needed? Answer: If the database was previously attached, SQL Server does not reattach it (it uses the attached database as the default for the connection).
Using "User Instance" on a local SQL Server Express instance:
"Data Source=.\SQLExpress;integrated security=true;attachdbfilename=|DataDirectory|\mydb.mdf;user instance=true;"
The "User Instance" functionality creates a new SQL Server instance on the fly during connect. This works only on a local SQL Server 2005 instance and only when connecting using windows authentication over local named pipes. The purpose is to be able to create a full rights SQL Server instance to a user with limited administrative rights on the computer. To enable the functionality: sp_configure 'user instances enabled','1' (0 to disable)
Using SQL Server 2005 Express? Don't miss the server name syntax: SERVERNAME\SQLEXPRESS (Substitute "SERVERNAME" with the name of the computer)
如果要进行同步/异步访问需要在字符串后面继续添加 Asynchronous Processing=true 默认关闭
如果要开启 MARS 则加上 MultipleActiveResultSets=True 默认开启。
相关文章推荐
- sql 2005 连接字符串
- ASP与SQL数据库连接及SQL常用命令使用方法
- 常用连接字符串
- SQL连接字符串大全
- [转]C# 多个项目共享配置文件(共用一个SQL连接字符串)
- 代码详解C#中SQL连接字符串的功能
- mysql 连接字符串与SQL不同
- 常用数据库的连接字符串的设置
- C# 常用数据库连接字符串【转】
- Sql注入中连接字符串常用函数
- string.Format连接sql字符串
- 常用的jdbc连接字符串
- sql 练习---连接某字段的值给一个字符串
- C# 连接SQL数据库 常用连接字符串
- SQL连接字符串大全
- Java中的JDBC常用的连接字符串
- 字符串常用操作的源码,拷贝、连接、比较、子串匹配
- 【译】ASP.NET MVC 5 教程 - 5:使用 SQL 服务器 LocalDB 创建连接字符串
- Sql-Server 配置远程连接以及C#连接字符串
- Oracle Sql 中常用字符串处理函数