ADO.NET连接字符串

本文涉及的产品
云数据库 RDS SQL Server,独享型 2核4GB
简介:
2008-04-15 12:49
名称
ADO.NET连接字符串
说明 ADO.NET连接字符串:SQL Server,SQL Server 2005,ACCESS,Oracle,MySQL,Interbase,IBM DB2,Sybase,Informix,Ingres,Mimer SQL,Lightbase,PostgreSQL,Paradox,DNS,Firebird,Excel ,Text,DBF / FoxPro,AS/400 (iSeries),Exchange,Visual FoxPro,Pervasive,UDL。

1 - SQL Server
2 - SQL Server 2005
3 - ACCESS, Oracle
4 - MySQL, Interbase, IBM DB2
5 - Sybase, Informix, Ingres, Mimer SQL, Lightbase, PostgreSQL, Paradox, DNS
6 - Firebird, Excel , Text, DBF / FoxPro, AS/400 (iSeries), Exchange, Visual FoxPro, Pervasive, UDL
1
SQL Server
ODBC
标准安全 " Driver={SQL Server}; Server=Aron1; Database=pubs; Uid=sa; Pwd=asdasd; "
信任的连接 " Driver={SQL Server}; Server=Aron1; Database=pubs; Trusted_Connection=yes; "
提示输入用户名和密码 oConn.Properties(" Prompt" ) = adPromptAlways
oConn.Open " Driver={SQL Server}; Server=Aron1; DataBase=pubs; "
OLE DB, OleDbConnection (.NET)
标准安全 " Provider=sqloledb; Data Source=Aron1; Initial Catalog=pubs; User Id=sa; Password=asdasd; "
信任的连接 " Provider=sqloledb; Data Source=Aron1; Initial Catalog=pubs; Integrated Security=SSPI; "
(use serverName\instanceName as Data Source to use an specifik SQLServer instance, only SQLServer2000)
提示输入用户名和密码 oConn.Provider = " sqloledb"
oConn.Properties(" Prompt" ) = adPromptAlways
oConn.Open " Data Source=Aron1; Initial Catalog=pubs; "
IP地址连接管道 " Provider=sqloledb; Data Source=190.190.200.100,1433; Network Library=DBMSSOCN; Initial Catalog=pubs; User ID=sa; Password=asdasd; "
(DBMSSOCN=TCP/IP instead of Named Pipes, at the end of the Data Source is the port to use (1433 is the default))
SqlConnection (.NET)
标准安全 " Data Source=Aron1; Initial Catalog=pubs; User Id=sa; Password=asdasd; "
- or -
" Server=Aron1; Database=pubs; User ID=sa; Password=asdasd; Trusted_Connection=False"
(both connection strings produces the same result)
信任的连接 " Data Source=Aron1; Initial Catalog=pubs; Integrated Security=SSPI; "
- or -
" Server=Aron1; Database=pubs; Trusted_Connection=True; "
(both connection strings produces the same result)
(use serverName\instanceName as Data Source to use an specifik SQLServer instance, only SQLServer2000)
IP地址连接管道 " Data Source=190.190.200.100,1433; Network Library=DBMSSOCN; Initial Catalog=pubs; User ID=sa; Password=asdasd; "
(DBMSSOCN=TCP/IP instead of Named Pipes, at the end of the Data Source is the port to use (1433 is the default))
定义SqlConnection对象 C#:
using System.Data.SqlClient;
SqlConnection oSQLConn = new SqlConnection();
oSQLConn.ConnectionString=" my connection string" ;
oSQLConn.Open();
VB.NET:
Imports System.Data.SqlClient
Dim oSQLConn As SqlConnection = New SqlConnection()
oSQLConn.ConnectionString=" my connection string"
oSQLConn.Open()
Data Shape
MS Data Shape " Provider=MSDataShape; Data Provider=SQLOLEDB; Data Source=Aron1; Initial Catalog=pubs; User ID=sa; Password=asdasd; "
2
SQL Server 2005
SQL Native Client ODBC Driver
标准安全 " Driver={SQL Native Client}; Server=Aron1; Database=pubs; UID=sa; PWD=asdasd; "
信任的连接 " Driver={SQL Native Client}; Server=Aron1; Database=pubs; Trusted_Connection=yes; "
Equivalents
Integrated Security=SSPI equals Trusted_Connection=yes
提示输入用户名和密码 oConn.Properties(" Prompt" ) = adPromptAlways
oConn.Open " Driver={SQL Native Client}; Server=Aron1; DataBase=pubs; "
授权的MARS(多重活动结果集) " Driver={SQL Native Client}; Server=Aron1; Database=pubs; Trusted_Connection=yes; MARS_Connection=yes"
Equivalents
MultipleActiveResultSets=true equals MARS_Connection=yes
加密数据网络传输 " Driver={SQL Native Client}; Server=Aron1; Database=pubs; Trusted_Connection=yes; Encrypt=yes"
在本地SQL服务器实例附加数据库文件 " Driver={SQL Native Client}; Server=.\SQLExpress; AttachDbFilename=c:\asd\qwe\mydbfile.mdf; Database=dbname; Trusted_Connection=Yes; "
- or -
" Driver={SQL Native Client}; Server=.\SQLExpress; AttachDbFilename=|DataDirectory|mydbfile.mdf; Database=dbname; Trusted_Connection=Yes; "
(use |DataDirectory| when your database file resides in the data directory)
SQL Native Client OLE DB Provider
标准安全 " Provider=SQLNCLI; Server=Aron1; Database=pubs; UID=sa; PWD=asdasd; "
信任的连接 " Provider=SQLNCLI; Server=Aron1; Database=pubs; Trusted_Connection=yes; "
Equivalents
Integrated Security=SSPI equals Trusted_Connection=yes
提示输入用户名和密码 oConn.Properties(" Prompt" ) = adPromptAlways
oConn.Open " Provider=SQLNCLI; Server=Aron1; DataBase=pubs; "
授权的MARS(多重活动结果集) " Provider=SQLNCLI; Server=Aron1; Database=pubs; Trusted_Connection=yes; MarsConn=yes"
Equivalents
MarsConn=yes equals MultipleActiveResultSets=true equals MARS_Connection=yes
加密数据网络传输 " Provider=SQLNCLI; Server=Aron1; Database=pubs; Trusted_Connection=yes; Encrypt=yes"
在本地SQL服务器实例附加数据库文件 " Provider=SQLNCLI; Server=.\SQLExpress; AttachDbFilename=c:\asd\qwe\mydbfile.mdf; Database=dbname; Trusted_Connection=Yes; "
- or -
" Provider=SQLNCLI; Server=.\SQLExpress; AttachDbFilename=|DataDirectory|mydbfile.mdf; Database=dbname; Trusted_Connection=Yes; "
(use |DataDirectory| when your database file resides in the data directory)
SqlConnection (.NET)
标准安全 " Data Source=Aron1; Initial Catalog=pubs; User Id=sa; Password=asdasd; "
- or -
" Server=Aron1; Database=pubs; User ID=sa; Password=asdasd; Trusted_Connection=False"
(both connection strings produces the same result)
信任的连接 " Data Source=Aron1; Initial Catalog=pubs; Integrated Security=SSPI; "
- or -
" Server=Aron1; Database=pubs; Trusted_Connection=True; "
(both connection strings produces the same result)
IP地址连接管道 " Data Source=190.190.200.100,1433; Network Library=DBMSSOCN; Initial Catalog=pubs; User ID=sa; Password=asdasd; "
(DBMSSOCN=TCP/IP instead of Named Pipes, at the end of the Data Source is the port to use (1433 is the default))
授权的MARS(多重活动结果集) " 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
在本地SQL服务器实例附加数据库文件 " Server=.\SQLExpress; AttachDbFilename=c:\asd\qwe\mydbfile.mdf; Database=dbname; Database=dbname; Trusted_Connection=Yes; "
- or -
" Server=.\SQLExpress; AttachDbFilename=|DataDirectory|mydbfile.mdf; Database=dbname; Trusted_Connection=Yes; "
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)
Context Connection - connecting to " self" from within your CLR stored prodedure/function
Context Connection - connecting to " self" from within your CLR stored prodedure/function
C# using(SqlConnection connection = new SqlConnection("context connection=true"))
{
connection.Open();
// Use the connection
}
Visual Basic Using connection as new SqlConnection("context connection=true")
connection.Open()
' Use the connection
End Using
Read more
When to use SQL Native Client? .Net applications
Do not use the SQL Native Client. Use the .NET Framework Data Provider for SQL Server (SqlConnection).
COM applications, all other then .Net applications
COM applications, all other then .Net applications
Use the SQL Native Client if you are accessing an SQL Server 2005 and need the new features of SQL Server 2005 such as MARS, encryption, XML data type etc. Continue use your current provider (OLE DB / ODBC through the MDAC package) if you are not connecting to an SQL Server 2005 (that's quite obvious eh..) or if you are connecting to an SQL Server 2005 but are not using any of the new SQL Server 2005 features.



本文转自 xhinkerx 51CTO博客,原文链接:http://blog.51cto.com/xhinker/131935,如需转载请自行联系原作者
相关实践学习
使用SQL语句管理索引
本次实验主要介绍如何在RDS-SQLServer数据库中,使用SQL语句管理索引。
SQL Server on Linux入门教程
SQL Server数据库一直只提供Windows下的版本。2016年微软宣布推出可运行在Linux系统下的SQL Server数据库,该版本目前还是早期预览版本。本课程主要介绍SQLServer On Linux的基本知识。 相关的阿里云产品:云数据库RDS SQL Server版 RDS SQL Server不仅拥有高可用架构和任意时间点的数据恢复功能,强力支撑各种企业应用,同时也包含了微软的License费用,减少额外支出。 了解产品详情: https://www.aliyun.com/product/rds/sqlserver
目录
相关文章
|
SQL 数据库 数据安全/隐私保护
ADO.NET 连接数据库方式
使用Command和DataReader对象:
55 0
|
XML SQL Oracle
ADO与ADO.net不同
ADO与ADO.net不同
96 0
ADO与ADO.net不同
|
SQL 安全 索引
|
Web App开发 数据库连接 数据库
|
安全 数据库