sql server 資料庫連線方式分析 詳解

2021-06-22 14:20:38 字數 2727 閱讀 5408

sql身份驗證模式:provider="sqloledb;data source=server_name;initial catalog=databasename;uid=username;pwd=password;"

1.provider=sqloledb:提供者為sqloledb(此為固定)

2.integrated security=sspi:

整合安全機制採用

sspi

sspi

是security support provider inte***ce(microsoft安全支援提供器介面)sspi是定義得較全面的公用api,用來獲得驗證、資訊完整性、資訊隱私等整合安全服務,以  及用於所有分布式應用程式協議的安全方面的服務。

設定integrated security為 true 的時候,採用windows身份驗證模式。只有設定為 false 或省略該項的時候,採用 userid, pwd 來連線。integrated security 可以設定為: true, false, yes, no ,還可以設定為:sspi ,相當於 true,建議用這個代替 true。

3.persist security info:堅持安全資訊

persist security info屬性的意思是表示是否儲存安全資訊,其實可以簡單的理解為"ado在資料庫連線成功後是否儲存密碼資訊",true表示儲存,false表示不儲存.ado預設為false(即可有可無).總體來說,如果資料庫連線成功後不再需要連線的密碼,出於安全性考慮,還是建議將persist security info設為false,以防止後門程式取得資料庫連線的密碼.

4.initial catalog等同於database(可以互換):指定連線資料庫的名字(如果省略則連線的是當前使用者名稱的預設資料庫,詳情見下文)

5.data source是sql伺服器的名字

在data source裡用localhost或(local)或「.」都代表本地伺服器. 也可用本機的外網ip位址 例如:data source=192.168.24.71;

使用資料來源方式

此種方式主要是配置odbc資料來源,有三種方式,系統dsn、使用者dsn、檔案dsn。具體方法這裡不作介紹。配置完資料來源以後即可連線:

用系統dsn:  connectstring= "dsn=dsnname;   uid=username;   pwd=password"

用檔案dsn:   connectstring = "filedsn=filedsnname; uid= username;   pwd=password "  

使用odbc驅動方式:

使用odbc 驅動程式, 免去了配置odbc資料來源的步驟, 可以利用odbc 驅動程式直接與資料庫相連線。

詳細注釋(關於windows身份驗證和sql身份驗證):

windows身份驗證使用windows登入使用者身份連線資料庫,而sql身份驗證要求顯式地指定sql server使用者id和密碼。要想使用windows身份驗證,必須在連線字串中包括 integrated security 屬性

:data source=servername;integrated security=true;

預設情況下,integrated security 屬性為 false ,這意味著將禁用windows身份驗證。如果沒有顯式地把這個屬性的值設定為true,連線將使用sql server身份驗證,因此,必須提供sql server使用者id和密碼。integrated security屬性還能識別的其他值只有sspi(security support provider inte***ce,安全性支援提供者介面).在所有的windows nt作業系統上,其中包括windows nt 4.0、2000、xp,都支援值sspi。它是使用windows身份驗證時可以使用的惟一介面,相當於把integrated security 屬性值設定為true。

在windows身份驗證模式中,sql server使用windows的安全子系統對使用者連線進行有效性驗證。即使顯示地指定使用者id和密碼,sql server也不檢查連線字串中的使用者id和密碼。因為只有windows nt、2000、xp支援sspi,因此如果正使用的是這些作業系統,則只能使用windows整合的安全策略去連線sql server。不論使用哪乙個作業系統,當使用sql server身份驗證時,必須在連線字串中指定使用者id和密碼:

data source=servername;user id=donaldx;password=unbreakable

預設情況下,sql server 每乙個使用者都可指定乙個預設資料庫,當在資料庫中建立使用者時,可以設定使用者的預設資料庫。此外,也可以在任意時間更改使用者的預設資料庫。:如下圖

設定好預設資料庫後在連線時可以不指定database(或initial catalog)的值即可連線預設資料庫.

資料庫連線 SQLServer

private static logger logger logger.getlogger test.class 驅動 private static final string driver com.microsoft.sqlserver.jdbc.sqlserverdriver 連線路徑 priva...

sql server資料庫連線

建立資料庫 表以及有關的sql語句 建立資料庫 create database winstudent 建立表 use winstudent goif exists select from sysobjects where name stuinfo drop table stuinfo create ...

perl 連線sql server資料庫

本質上是和連線mysql一樣的,但是需要配置很多東西 先看 use dbi my dsn driver server 192.168.1.213 database msy uid perlname pwd x my dbh dbi connect dbi odbc dsn or die couldn...