" 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)
" 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; "
" 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
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.
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\somepath\mydb.mdb; User Id=admin; Password=; "
工作组 (system database)
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\somepath\mydb.mdb; Jet OLEDB:System Database=system.mdw; "
使用密码
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\somepath\mydb.mdb; Jet OLEDB:Database Password=MyDbPassword; "
Oracle
ODBC
新版本
"Driver={Microsoft ODBC for Oracle}; Server=OracleServer.world; Uid=Username; Pwd=asdasd; "
旧版本
"Driver={Microsoft ODBC Driver for Oracle}; ConnectString=OracleServer.world; Uid=myUsername; Pwd=myPassword; "
OLE DB, OleDbConnection (.NET)
标准安全
"Provider=msdaora; Data Source=MyOracleDB; User Id=UserName; Password=asdasd; " This one's from Microsoft, the following are from Oracle
标准安全
"Provider=OraOLEDB.Oracle; Data Source=MyOracleDB; User Id=Username; Password=asdasd; "
信任的连接
"Provider=OraOLEDB.Oracle; Data Source=MyOracleDB; OSAuthent=1; "
OracleConnection (.NET)
标准
"Data Source=MyOracleDB; Integrated Security=yes; " This one works only with Oracle 8i release 3 or later
指定用户名和密码
"Data Source=MyOracleDB; User Id=username; Password=passwd; Integrated Security=no; " This one works only with Oracle 8i release 3 or later
定义OracleConnection对象
C#: using System.Data.OracleClient; OracleConnection oOracleConn = new OracleConnection(); oOracleConn.ConnectionString = "my connection string"; oOracleConn.Open();
VB.NET: Imports System.Data.OracleClient Dim oOracleConn As OracleConnection = New OracleConnection() oOracleConn.ConnectionString = "my connection string" oOracleConn.Open()
Core Labs OraDirect (.NET)
标准
"User ID=scott; Password=tiger; Host=ora; Pooling=true; Min Pool Size=0; Max Pool Size=100; Connection Lifetime=0"
Data Shape
微软数据模型
"Provider=MSDataShape.1; Persist Security Info=False; Data Provider=MSDAORA; Data Source=orac; user id=username; password=mypw"
"Provider=MySQLProv; Data Source=mydb; User Id=UserName; Password=asdasd; "
Connector/Net 1.0 (.NET)
标准
"Server=Server; Database=Test; Uid=UserName; Pwd=asdasd; " Download the driver at MySQL Developer Zone
指定端口
"Server=Server; Port=1234; Database=Test; Uid=UserName; Pwd=asdasd; " Default port is 3306. Enter value -1 to use a named pipe connection.
定义mysqlclient 连接对象
C#: using MySql.Data.MySqlClient; MySqlConnection oMySqlConn = new MySqlConnection(); oMySqlConn.ConnectionString = "Server=Server; Database=Test; Uid=UserName; Pwd=asdasd; "; oMySqlConn.Open();
VB.NET: Imports MySql.Data.MySqlClient Dim oMySqlConn As MySqlConnection = New MySqlConnection() oMySqlConn.ConnectionString = "Server=Server; Database=Test; Uid=UserName; Pwd=asdasd; " oMySqlConn.Open()
MySqlConnection (.NET)
eInfoDesigns.dbProvider
"Data Source=server; Database=mydb; User ID=username; Password=pwd; Command Logging=false" This one is used with eInfoDesigns dbProvider, an add-on to .NET
定义MySqlConnection连接对象
C#: using eInfoDesigns.dbProvider.MySqlClient; MySqlConnection oMySqlConn = new MySqlConnection(); oMySqlConn.ConnectionString = "my connection string"; oMySqlConn.Open();
VB.NET: Imports eInfoDesigns.dbProvider.MySqlClient Dim oMySqlConn As MySqlConnection = New MySqlConnection() oMySqlConn.ConnectionString = "my connection string" oMySqlConn.Open()
SevenObjects MySqlClient (.NET)
标准
"Host=server; UserName=myusername; Password=mypassword; Database=mydb; " This is a freeware ADO.Net data provider from SevenObjects
Core Labs MySQLDirect (.NET)
标准
"User ID=root; Password=pwd; Host=localhost; Port=3306; Database=test; Direct=true; Protocol=TCP; Compress=false; Pooling=true; Min Pool Size=0; Max Pool Size=100; Connection Lifetime=0"
"provider=sibprovider; location=localhost:; data source=c:\databases\gdbs\mygdb.gdb; user id=SYSDBA; password=masterkey"
指定字符集
"provider=sibprovider; location=localhost:; data source=c:\databases\gdbs\mygdb.gdb; user id=SYSDBA; password=masterkey; character set=ISO8859_1"
指定规则
"provider=sibprovider; location=localhost:; data source=c:\databases\gdbs\mygdb.gdb; user id=SYSDBA; password=masterkey; role=DIGITADORES"
IBM DB2
OLE DB, OleDbConnection (.NET) from ms
TCP/IP
"Provider=DB2OLEDB; Network Transport Library=TCPIP; Network Address=XXX.XXX.XXX.XXX; Initial Catalog=MyCtlg; Package Collection=MyPkgCol; Default Schema=Schema; User ID=MyUser; Password=MyPW"
APPC
"Provider=DB2OLEDB; APPC Local LU Alias=MyAlias; APPC Remote LU Alias=MyRemote; Initial Catalog=MyCtlg; Package Collection=MyPkgCol; Default Schema=Schema; User ID=MyUser; Password=MyPW"
IBM's OLE DB Provider (shipped with IBM DB2 UDB v7 or above)
Adaptive Server Enterprise (ASE) with Data Source .IDS file
"Provider=Sybase ASE OLE DB Provider; Data source=myASE"
Adaptive Server Enterprise (ASE)
"Provider=Sybase.ASEOLEDBProvider; Srvr=myASEserver,5000; Catalog=myDBname; User Id=username; Password=password" - some reports on problem using the above one, try the following as an alternative -
"Provider=Sybase.ASEOLEDBProvider; Server Name=myASEserver,5000; Initial Catalog=myDBname; User Id=username; Password=password" This one works only from Open Client 12.5 where the server port number feature works,following fully qualified connection strings to be used without definingfony .IDS Data Source files.
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\MyExcel.xls; Extended Properties=""Excel 8.0; HDR=Yes; IMEX=1""" "HDR=Yes; " indicates that the first row contains columnnames, not data "IMEX=1; " tells the driver to always read "intermixed" data columns as text TIP! SQL syntax: "SELECT * FROM [sheet1$]" - i.e. worksheet name followed by a "$" and wrapped in "[" "]" brackets.
Text
ODBC
标准
"Driver={Microsoft Text Driver (*.txt; *.csv)}; Dbq=c:\txtFilesFolder\; Extensions=asc,csv,tab,txt; "
OLE DB
标准
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\txtFilesFolder\; Extended Properties=""text; HDR=Yes; FMT=Delimited""" "HDR=Yes; " indicates that the first row contains columnnames, not data
昵称:
退出登录 订阅评论
[Ctrl+Enter快捷键提交]
· Airbnb去年清掉923处不合规定的房源
· 谷歌开源“Guetzli”JPEG图像编码器:提升压缩比、网页加载更顺滑
· 万宝龙推出首款Android Wear智能手表
· Apple Music大使计划 推特推广可免费获得3个月会员
· Windows 10 Build 15060发布:本周的第三个版本更新
» 更多新闻...
· 垃圾回收原来是这么回事
· 「代码家」的学习过程和学习经验分享
· 写给未来的程序媛
· 高质量的工程代码为什么难写