程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> 其他數據庫知識 >> MSSQL2008 >> sql server 2008數據庫銜接字符串年夜全

sql server 2008數據庫銜接字符串年夜全

編輯:MSSQL2008

sql server 2008數據庫銜接字符串年夜全。本站提示廣大學習愛好者:(sql server 2008數據庫銜接字符串年夜全)文章只能為提供參考,不一定能成為您想要的結果。以下是sql server 2008數據庫銜接字符串年夜全正文


1、.NET Framework Data Provider for SQL Server
類型:.NET Framework類庫
應用:System.Data.SqlClient.SqlConnection
廠商:Microsoft

1.尺度平安銜接
Data Source = myServerAddress;Initial Catalog = myDataBase;User Id = myUsername;Password = myPassword;
應用辦事器名\實例名作為銜接指定SQL Server實例的數據源。假如你應用的是SQL Server 2008 Express版,實例名為SQLEXPRESS。
2.可替換的尺度平安銜接
Server = myServerAddress;Database = myDataBase;User ID = myUsername;Password = myPassword;Trusted_Connection = False;
這條銜接字符串跟上一條後果一樣。把這條寫出來只是想說,其實許多銜接字符串的症結字有多種寫法。
3.信賴銜接
Data Source = myServerAddress;Initial Catalog = myDataBase;Integrated Security = SSPI;
可替換的信賴銜接
Server = myServerAddress;Database = myDataBase;Trusted_Connection = True;
4.銜接Windows CE裝備的信賴銜接
平日一台Windows CE裝備在一個域裡是不克不及被認證和登錄的。為了讓一台CE裝備應用SSPI或信賴銜接和認證,可使用上面的銜接字符串:
Data Source = myServerAddress;Initial Catalog = myDataBase;Integrated Security = SSPI;User ID = myDomain
\myUsername;Password = myPassword;
解釋一下,這條語句只能在CE裝備上用。
5.應用IP地址的銜接
Data Source = 190.168.1.100,1433;Network Library = DBMSSOCN;Initial Catalog = myDataBase;User
ID = myUsername;Password = myPassword;
這條語句用TCP/IP地址替換了定名管道。在Data Source字段最初的是應用的端口。SQL Server默許應用的端口是1433。
6.開啟MARS功效(multiple active result sets)
Server = myServerAddress;Database = myDataBase;Trusted_Connection = True; MultipleActiveResultSets = true;
MARS不支撐ADO.NET 1.0和ADO.NET 1.1。
7.在銜接到SQL Server Express實例時附加一個數據庫文件

Server = .\SQLExpress;AttachDbFilename = c:\asd\qwe\mydbfile.mdf;Database = dbname; Trusted_Connection = Yes;
這裡為何還須要Database字段呢?由於假如指定的數據庫文件曾經被附加,那末SQL Server不會再附加它,而應用已附加的數據庫作為默許數據庫。

8.在銜接到SQL Server Express實例時,從數據目次下附加一個數據庫文件
Server = .\SQLExpress;AttachDbFilename = |DataDirectory|mydbfile.mdf; Database = dbname;Trusted_Connection = Yes;

9.在當地SQL Server Express實例上應用用戶實例
用戶實例這個功效會在銜接的進程中,新建一個SQL Server實例。該功效只要在當地SQL Server實例上,且銜接時應用經由過程當地定名通道的Windows認證。如許做的利益是,可以給一個在當地盤算機上只要相當無限的治理員權限的用戶,新建一個具有全體權限的SQL Server實例。
Data Source = .\SQLExpress;Integrated Security = true; AttachDbFilename = |DataDirectory|\mydb.mdf;User Instance = true;
若想應用用戶實例這個功效,須要先在SQL Server將其開啟。開啟敕令為:

sp_configure 'user instances enabled', '1'

撤消敕令為:

sp_configure 'user instances enabled', '0'

注:這兩條敕令只在SQL Server Express中有用。

 

10.數據庫鏡像
假如你用ADO.NET或許SQL Native Client去銜接一個數據庫鏡像,當這個數據庫鏡像停止毛病切換的時刻,你的運用法式可以應用驅動器的特征去主動重定向銜接。固然,你必需在銜接字段裡指定初始的主辦事器和數據庫,和用於毛病切換的鏡像辦事器。

Data Source = myServerAddress;Failover Partner = myMirrorServerAddress;Initial Catalog = myDataBase;Integrated
Security = True;
下面的例子只是引見了一下若何應用數據庫鏡像,你可以將Failover Partner字段跟其他銜接字符串功效組合應用。


11.異步處置
Server = myServerAddress;Database = myDataBase;Integrated Security = True;Asynchronous Processing = True;

2、SQL Server Native Client 10.0 OLE DB Provider

類型:OLE DB Provider
應用:Provider=SQLNCLI10
廠商:Microsoft


1.尺度平安銜接
Provider = SQLNCLI10;Server = myServerAddress;Database = myDataBase;Uid = myUsername; Pwd = myPassword;
2.信賴銜接
Provider = SQLNCLI10;Server = myServerAddress;Database = myDataBase; Trusted_Connection = yes;
 "Integrated Security=SSPI" 和 "Trusted_Connection=yes"是等價的。
3.銜接一個SQL Server實例
Provider = SQLNCLI10;Server = myServerName\theInstanceName;Database = myDataBase; Trusted_Connection = yes;

4.用戶名、暗碼提醒
oConn.Properties("Prompt") = adPromptAlways
oConn.Open "Provider = SQLNCLI10;Server = myServerAddress;DataBase = myDataBase;
5.開啟MARS功效 (multiple active result sets)
Provider = SQLNCLI10;Server = myServerAddress;Database = myDataBase; Trusted_Connection = yes;MARS Connection = True;
6.加密形式
Provider = SQLNCLI10;Server = myServerAddress;Database = myDataBase; Trusted_Connection = yes;Encrypt = yes;
7.在銜接到SQL Server Express實例時附加一個數據庫文件
Provider = SQLNCLI10;Server = .\SQLExpress;AttachDbFilename = c:\asd\qwe\mydbfile.mdf; Database = dbname;
Trusted_Connection = Yes;
8.在銜接到SQL Server Express實例時,從數據目次下附加一個數據庫文件
Provider = SQLNCLI10;Server = .\SQLExpress;AttachDbFilename = |DataDirectory|mydbfile.mdf;
Database = dbname;Trusted_Connection = Yes;
9.數據庫鏡像
Provider = SQLNCLI10;Data Source = myServerAddress;Failover Partner = myMirrorServerAddress;Initial
Catalog = myDataBase;Integrated Security = True;
 

3、.NET Framework Data Provider for OLE DB

類型:.NET Framework Wrapper Class Library
應用:System.Data.OleDb.OleDbConnection
廠商:Microsoft


1.橋接到SQL Native Client OLE DB
Provider = SQLNCLI10;Server = myServerAddress;Database = myDataBase;Uid = myUsername; Pwd = myPassword;

4、SQL Server Native Client 10.0 ODBC Driver

類型:ODBC Driver
應用:Driver={SQL Server Native Client 10.0}
廠商:Microsoft

1.尺度平安銜接
Driver = {SQL Server Native Client 10.0};Server = myServerAddress;Database = myDataBase;Uid = myUsername;Pwd = myPassword;
2.信賴銜接
Driver = {SQL Server Native Client 10.0};Server = myServerAddress;Database = myDataBase;Trusted_Connection = yes;
3.銜接一個SQL Server實例
Driver = {SQL Server Native Client 10.0};Server = myServerName\theInstanceName;
Database = myDataBase;Trusted_Connection = yes;
4.用戶名、暗碼提醒
Conn.Properties("Prompt") = adPromptAlways
Driver = {SQL Server Native Client 10.0};Server = myServerAddress;Database = myDataBase;
5.開啟MARS功效 (multiple active result sets)
Driver = {SQL Server Native Client 10.0};Server = myServerAddress;Database = myDataBase;Trusted_Connection = yes;
MARS_Connection = yes;
6.加密形式
Driver = {SQL Server Native Client 10.0};Server = myServerAddress;Database = myDataBase;
Trusted_Connection = yes;Encrypt = yes;
7.在銜接到SQL Server Express實例時附加一個數據庫文件
Driver = {SQL Server Native Client 10.0};Server = .\SQLExpress; AttachDbFilename = c:\asd\qwe\mydbfile.mdf;
Database = dbname;Trusted_Connection = Yes;
8.在銜接到SQL Server Express實例時,從數據目次下附加一個數據庫文件
Driver={SQL Server Native Client 10.0};Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;
Database=dbname;Trusted_Connection=Yes;
9.數據庫鏡像
Driver = {SQL Server Native Client
10.0};Server = myServerAddress;Failover_Partner = myMirrorServerAddress;Database = myDataBase; Trusted_Connection = yes;

5、.NET Framework Data Provider for ODBC

類型:.NET Framework Wrapper Class Library
應用:System.Data.Odbc.OdbcConnection
廠商:Microsoft

橋接到SQL Native Client 10.0 ODBC Driver
上面的語句只是一條例子,分歧廠商的ODBC驅動分歧。

Driver={SQL Server Native Client 10.0};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
 

6、SQLXML 4.0 OLEDB Provider

類型:OLE DB Provider
應用:Provider=SQLXMLOLEDB.4.0;Data Provider=providername
廠商:Microsoft

Provider=SQLXMLOLEDB.4.0;Data Provider=SQLNCLI10;Data Source=myServerAddress;Initial Catalog=myDataBase;User
Id=myUsername;Password=myPassword;

7、Context Connection

類型:.NET Framework Class Library
應用:
廠商:Microsoft

經由過程以後CLR裡的存儲進程/函數來銜接到“本身”。高低文銜接可讓你,在你的代碼第一次被挪用的處所地點的高低文(銜接)裡,履行T-SQL語句。
C#:

 

using(SqlConnection connection = new SqlConnection("context connection=true"))
{
    connection.Open();
    // Use the connection
}


VB.Net

Using connection as new SqlConnection("context connection=true")
    connection.Open()
    ' Use the connection
End Using


 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved