数据库连接字符串大全.docx
- 文档编号:17275977
- 上传时间:2023-07-23
- 格式:DOCX
- 页数:20
- 大小:20.35KB
数据库连接字符串大全.docx
《数据库连接字符串大全.docx》由会员分享,可在线阅读,更多相关《数据库连接字符串大全.docx(20页珍藏版)》请在冰点文库上搜索。
数据库连接字符串大全
SQLServer
∙ ODBC
∙ StandardSecurity:
"Driver={SQLServer};Server=Aron1;Database=pubs;Uid=sa;Pwd=asdasd;"
∙ Trustedconnection:
"Driver={SQLServer};Server=Aron1;Database=pubs;Trusted_Connection=yes;"
∙ Promptforusernameandpassword:
oConn.Properties("Prompt")=adPromptAlways
oConn.Open"Driver={SQLServer};Server=Aron1;DataBase=pubs;"
∙ OLEDB,OleDbConnection(.NET)
∙ StandardSecurity:
"Provider=sqloledb;DataSource=Aron1;InitialCatalog=pubs;UserId=sa;Password=asdasd;"
∙ TrustedConnection:
"Provider=sqloledb;DataSource=Aron1;InitialCatalog=pubs;IntegratedSecurity=SSPI;"
(useserverName\instanceNameasDataSourcetouseanspecifikSQLServerinstance,onlySQLServer2000)
∙ Promptforusernameandpassword:
oConn.Provider="sqloledb"
oConn.Properties("Prompt")=adPromptAlways
oConn.Open"DataSource=Aron1;InitialCatalog=pubs;"
∙ ConnectviaanIPaddress:
"Provider=sqloledb;DataSource=190.190.200.100,1433;NetworkLibrary=DBMSSOCN;InitialCatalog=pubs;UserID=sa;Password=asdasd;"
(DBMSSOCN=TCP/IPinsteadofNamedPipes,attheendoftheDataSourceistheporttouse(1433isthedefault))
∙ SqlConnection(.NET)
∙ StandardSecurity:
"DataSource=Aron1;InitialCatalog=pubs;UserId=sa;Password=asdasd;"
- or -
"Server=Aron1;Database=pubs;UserID=sa;Password=asdasd;Trusted_Connection=False"
(boothconnectionstringsproducesthesameresult)
∙ TrustedConnection:
"DataSource=Aron1;InitialCatalog=pubs;IntegratedSecurity=SSPI;"
- or -
"Server=Aron1;Database=pubs;Trusted_Connection=True;"
(boothconnectionstringsproducesthesameresult)
(useserverName\instanceNameasDataSourcetouseanspecifikSQLServerinstance,onlySQLServer2000)
∙ ConnectviaanIPaddress:
"DataSource=190.190.200.100,1433;NetworkLibrary=DBMSSOCN;InitialCatalog=pubs;UserID=sa;Password=asdasd;"
(DBMSSOCN=TCP/IPinsteadofNamedPipes,attheendoftheDataSourceistheporttouse(1433isthedefault))
∙ DeclaretheSqlConnection:
C#:
usingSystem.Data.SqlClient;
SqlConnectionoSQLConn=newSqlConnection();
oSQLConn.ConnectionString="myconnectionstring";
oSQLConn.Open();
VB.NET:
ImportsSystem.Data.SqlClient
DimoSQLConnAsSqlConnection=NewSqlConnection()
oSQLConn.ConnectionString="myconnectionstring"
oSQLConn.Open()
∙ DataShape
∙ MSDataShape
"Provider=MSDataShape;DataProvider=SQLOLEDB;DataSource=Aron1;InitialCatalog=pubs;UserID=sa;Password=asdasd;"
Wanttolearndatashaping?
Checkout4GuyfFromRolla'sgreatarticleaboutDataShaping>>
∙ Readmore
∙ Howtodefinewichnetworkprotocoltouse
∙Example:
"Provider=sqloledb;DataSource=190.190.200.100,1433;NetworkLibrary=DBMSSOCN;InitialCatalog=pubs;UserID=sa;Password=asdasd;"
Name
Networklibrary
dbnmpntw
Win32NamedPipes
dbmssocn
Win32WinsockTCP/IP
dbmsspxn
Win32SPX/IPX
dbmsvinn
Win32BanyanVines
dbmsrpcn
Win32Multi-Protocol(WindowsRPC)
∙
Importantnote!
WhenconnectingthroughtheSQLOLEDBproviderusethesyntaxNetworkLibrary=dbmssocn
andwhenconnectingthroughMSDASQLproviderusethesyntaxNetwork=dbmssocn
∙ AllSqlConnectionconnectionstringproperties
∙ThistableshowsallconnectionstringpropertiesfortheADO.NETSqlConnectionobject.MostofthepropertiesarealsousedinADO.Allpropertiesanddescriptionsisfrommsdn.
Name
Default
Description
ApplicationName
Thenameoftheapplication,or'.NetSqlClientDataProvider'ifnoapplicationnameisprovided.
AttachDBFilename
-or-
extended properties
-or-
InitialFileName
Thenameoftheprimaryfile,includingthefullpathname,ofanattachabledatabase.Thedatabasenamemustbespecifiedwiththekeyword'database'.
ConnectTimeout
-or-
ConnectionTimeout
15
Thelengthoftime(inseconds)towaitforaconnectiontotheserverbeforeterminatingtheattemptandgeneratinganerror.
ConnectionLifetime
0
Whenaconnectionisreturnedtothepool,itscreationtimeiscomparedwiththecurrenttime,andtheconnectionisdestroyedifthattimespan(inseconds)exceedsthevaluespecifiedbyconnectionlifetime.Usefulinclusteredconfigurationstoforceloadbalancingbetweenarunningserverandaserverjustbroughton-line.
ConnectionReset
'true'
Determineswhetherthedatabaseconnectionisresetwhenbeingremovedfromthepool.Settingto'false'avoidsmakinganadditionalserverround-tripwhenobtainingaconnection,buttheprogrammermustbeawarethattheconnectionstateisnotbeingreset.
CurrentLanguage
TheSQLServerLanguagerecordname.
DataSource
-or-
Server
-or-
Address
-or-
Addr
-or-
NetworkAddress
ThenameornetworkaddressoftheinstanceofSQLServertowhichtoconnect.
Enlist
'true'
Whentrue,thepoolerautomaticallyenliststheconnectioninthecreationthread'scurrenttransactioncontext.
InitialCatalog
-or-
Database
Thenameofthedatabase.
IntegratedSecurity
-or-
Trusted_Connection
'false'
Whethertheconnectionistobeasecureconnectionornot.Recognizedvaluesare'true','false',and'sspi',whichisequivalentto'true'.
MaxPoolSize
100
Themaximumnumberofconnectionsallowedinthepool.
MinPoolSize
0
Theminimumnumberofconnectionsallowedinthepool.
NetworkLibrary
-or-
Net
'dbmssocn'
ThenetworklibraryusedtoestablishaconnectiontoaninstanceofSQLServer.Supportedvaluesincludedbnmpntw(NamedPipes),dbmsrpcn(Multiprotocol),dbmsadsn(AppleTalk),dbmsgnet(VIA),dbmsipcn(SharedMemory)anddbmsspxn(IPX/SPX),anddbmssocn(TCP/IP).
ThecorrespondingnetworkDLLmustbeinstalledonthesystemtowhichyouconnect.Ifyoudonotspecifyanetworkandyouusealocalserver(forexample,"."or"(local)"),sharedmemoryisused.
PacketSize
8192
SizeinbytesofthenetworkpacketsusedtocommunicatewithaninstanceofSQLServer.
Password
-or-
Pwd
ThepasswordfortheSQLServeraccountloggingon.
PersistSecurityInfo
'false'
Whensetto'false',security-sensitiveinformation,suchasthepassword,isnotreturnedaspartoftheconnectioniftheconnectionisopenorhaseverbeeninanopenstate.Resettingtheconnectionstringresetsallconnectionstringvaluesincludingthepassword.
Pooling
'true'
Whentrue,theSQLConnectionobjectisdrawnfromtheappropriatepool,orifnecessary,iscreatedandaddedtotheappropriatepool.
UserID
TheSQLServerloginaccount.
WorkstationID
thelocalcomputername
ThenameoftheworkstationconnectingtoSQLServer.
∙
Note
Use;toseparateeachproperty.
Ifanameoccursmorethanonce,thevaluefromthelastoneintheconnectionstringwillbeused.
Ifyouarebuildingyourconnectionstringinyourappusingvaluesfromuserinputfields,makesuretheusercan'tchangetheconnectionstringbyinsertinganadditionalpropertywithanothervaluewithintheuservalue.
Access
∙ ODBC
∙ StandardSecurity:
"Driver={MicrosoftAccessDriver(*.mdb)};Dbq=C:
\mydatabase.mdb;Uid=Admin;Pwd=;"
∙ Workgroup:
"Driver={MicrosoftAccessDriver(*.mdb)};Dbq=C:
\mydatabase.mdb;SystemDB=C:
\mydatabase.mdw;"
∙ Exclusive:
"Driver={MicrosoftAccessDriver(*.mdb)};Dbq=C:
\mydatabase.mdb;Exclusive=1;Uid=admin;Pwd="
∙ OLEDB,OleDbConnection(.NET)
∙ Standardsecurity:
"Provider=Microsoft.Jet.OLEDB.4.0;DataSource=\somepath\mydb.mdb;UserId=admin;Password=;"
∙ Workgroup(systemdatabase):
"Provider=Microsoft.Jet.OLEDB.4.0;DataSource=\somepath\mydb.mdb;JetOLEDB:
SystemDatabase=system.mdw;"
∙ Withpassword:
"Provider=Microsoft.Jet.OLEDB.4.0;DataSource=\somepath\mydb.mdb;JetOLEDB:
DatabasePassword=MyDbPassword;"
Oracle
∙ ODBC
∙ Newversion:
"Driver={MicrosoftODBCforOracle};Server=OracleServer.world;Uid=Username;Pwd=asdasd;"
∙ Oldversion:
"Driver={MicrosoftODBCDriverforOracle};ConnectString=OracleServer.world;Uid=myUsername;Pwd=myPassword;"
∙ OLEDB,OleDbConnection(.NET)
∙ Standardsecurity:
"Provider=msdaora;DataSource=MyOracleDB;UserId=UserName;Password=asdasd;"
Thisone'sfromMicrosoft,thefollowingarefromOracle
∙ StandardSecurity:
"Provider=OraOLEDB.Oracle;DataSource=MyOracleDB;UserId=Username;Password=asdasd;"
∙ TrustedConnection:
"Provider=OraOLEDB.Oracle;DataSource=MyOracleDB;OSAuthent=1;"
∙ OracleConnection(.NET)
∙ Standard:
"DataSource=Oracle8i;IntegratedSecurity=yes";
ThisoneworksonlywithOracle8irelease3orlater
∙ DeclaretheOracleConnection:
C#:
usingSystem.Data.OracleClient;
OracleConnectionoOracleConn=newOracleConnection();
oOracleConn.ConnectionString="myconnectionstring";
oOracleConn.Open();
VB.NET:
ImportsSystem.Data.OracleClient
DimoOracleConnAsOracleConnection=NewOracleConnection()
oOracleConn.ConnectionString="myconnectionstring"
oOracleConn.Open()
∙ CoreLabsOraDirect(.NET)
∙ Standard:
"UserID=scott;Password=tiger;Host=ora;Pooling=true;MinPoolSize=0;MaxPoolSize=100;ConnectionLifetime=0"
ReadmoreatCoreLabandtheproductpage.
∙ DataShape
∙ MSDataShape:
"Provider=MSDataShape.1;PersistSecurityInfo=False;DataProvider=MSDAORA;DataSource=orac;userid=username;password=mypw"
Wanttolearndatashaping?
Checkout4GuyfFromRolla'sgreatarticleaboutDataShaping>>
MySQL
∙ ODBC
∙ Localdatabase:
"Driver={mySQL};Server=mySrvName;Option=16834;Database=mydatabase;"
∙ Remotedatabase:
"Driver={mySQL};Server=;Port=3306;Option=131072;Stmt=;Database=my-database;Uid=username;Pwd=password;"
∙ OLEDB,OleDbConnection(.NET)
∙ Standard:
"Provider=MySQLProv;DataSource=mydb;UserId=UserName;Password=asdasd;"
∙ MySqlConnection(.NET)
∙ eInfoDesigns.dbProvider:
"DataSource=server;D
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据库连接 字符串 大全