数据库连接串大全.docx
《数据库连接串大全.docx》由会员分享,可在线阅读,更多相关《数据库连接串大全.docx(21页珍藏版)》请在冰豆网上搜索。
数据库连接串大全
ASE.NETDataProvider
MySQLDirect.NETDataProvider
ODBC.NETDataProvider
OLEDB.NETDataProvider
Oracle.NETDataProvider-FromMicrosoft
Oracle.NETDataProvider-FromOracle
OraDirect.NETDataProvider
PostgreSQLDirect.NETDataProvider
SQLServer.NETDataProvider
AdaptiveServerEnterprise(ASE).NETDataProvider
Sybase.Data.AseClient
UsingC#
usingSybase.Data.AseClient;
...
AseConnectionoAseConn=newAseConnection();
oAseConn.ConnectionString="DataSource=(local);"+
"InitialCatalog=myDatabaseName;"+
"UserID=myUsername;"+
"Password=myPassword"
oAseConn.Open();
UsingVB.NET
ImportsSystem.Data.AseClient
...
DimoAseConnAsAseConnection=NewAseConnection()
oAseConn.ConnectionString="DataSource=(local);"&_
"InitialCatalog=myDatabaseName;"&_
"UserID=myUsername;"&_
"Password=myPassword"
oAseConn.Open()
MySQLDirect.NETDataProvider
CoreLab.MySql
TheMySQLDirect.NETDataProviderisanadd-oncomponenttothe
.NETFrameworkthatallowsyoutoaccesstheMySQLdatabaseusing
nativeMySQLnetworkprotocolorMySQLclient,withoutgoingthrough
OLEDBorODBC.
UsingC#
usingCoreLab.MySql;
MySqlConnectionoMySqlConn=newMySqlConnection();
oMySqlConn.ConnectionString="UserID=myUsername;"+
"Password=myPassword;"+
"Host=localhost;"+
"Port=3306;"+
"Database=myDatabaseName;"+
"Direct=true;"+
"Protocol=TCP;"+
"Compress=false;"+
"Pooling=true;"+
"MinPoolSize=0;"+
"MaxPoolSize=100;"+
"ConnectionLifetime=0";
oMySqlConn.Open();
UsingVB.NET
ImportsCoreLab.MySql
DimoMySqlConnAsMySqlConnection=NewMySqlConnection()
oMySqlConn.ConnectionString="UserID=myUsername;"&_
"Password=myPassword;"&_
"Host=localhost;"&_
"Port=3306;"&_
"Database=myDatabaseName;"&_
"Direct=true;"&_
"Protocol=TCP;"&_
"Compress=false;"&_
"Pooling=true;"&_
"MinPoolSize=0;"&_
"MaxPoolSize=100;"&_
"ConnectionLifetime=0"
oMySqlConn.Open()
ODBC.NETDataProvider
System.Data.ODBC
TheODBC.NETDataProviderisanadd-oncomponenttothe.NETFramework1.0,andisincludedinthe.NETFramework1.1.
ItprovidesaccesstonativeODBCDriversthesamewaytheOLEDB.NETDataProviderprovidesaccesstonativeOLEDBproviders.
ForSQLServerODBCDriver
'VB.NET
ImportsSystem.Data.Odbc
...
DimoODBCConnectionAsOdbcConnection
DimsConnStringAsString=_
"Driver={SQLServer};"&_
"Server=MySQLServerName;"&_
"Database=MyDatabaseName;"&_
"Uid=MyUsername;"&_
"Pwd=MyPassword"
oODBCConnection=NewOdbc.OdbcConnection(sConnString)
oODBCConnection.Open()
ForOracleODBCDriver
'VB.NET
ImportsSystem.Data.Odbc
...
DimoODBCConnectionAsOdbcConnection
DimsConnStringAsString=_
"Driver={MicrosoftODBCforOracle};"&_
"Server=OracleServer.world;"&_
"Uid=myUsername;"&_
"Pwd=myPassword"
oODBCConnection=NewOdbc.OdbcConnection(sConnString)
oODBCConnection.Open()
ForAccess(JET)ODBCDriver
'VB.NET
ImportsSystem.Data.Odbc
...
DimoODBCConnectionAsOdbcConnection
DimsConnStringAsString=_
"Driver={MicrosoftAccessDriver(*.mdb)};"&_
"Dbq=c:
\somepath\mydb.mdb;"&_
"Uid=Admin;"&_
"Pwd="
oODBCConnection=NewOdbc.OdbcConnection(sConnString)
oODBCConnection.Open()
ForSybaseSystem11ODBCDriver
'VB.NET
ImportsSystem.Data.Odbc
...
DimoODBCConnectionAsOdbcConnection
DimsConnStringAsString=_
"Driver={SybaseSystem11};"&_
"SRVR=mySybaseServerName;"&_
"DB=myDatabaseName;"&_
"UID=myUsername;"&_
"PWD=myPassword"
oODBCConnection=NewOdbcConnection(sConnString)
oODBCConnection.Open()
ForallotherODBCDrivers
'VB.NET
ImportsSystem.Data.Odbc
...
DimoODBCConnectionAsOdbcConnection
DimsConnStringAsString="Dsn=myDsn;"&_
"Uid=myUsername;"&_
"Pwd=myPassword"
oODBCConnection=NewOdbc.OdbcConnection(sConnString)
oODBCConnection.Open()
OLEDB.NETDataProvider
System.Data.OleDb
TheOLEDB.NETDataProviderusesnativeOLEDBthroughCOMinteroptoenabledataaccess.
TousetheOLEDB.NETDataProvider,youmustalsouseanOLEDBprovider(e.g.SQLOLEDB,MSDAORA,orMicrosoft.JET.OLEDB.4.0).
ForIBMAS/400OLEDBProvider
'VB.NET
ImportsSystem.Data.OleDb
...
DimoOleDbConnectionAsOleDbConnection
DimsConnStringAsString=_
"Provider=IBMDA400.DataSource.1;"&_
"Datasource=myAS400DbName;"&_
"UserId=myUsername;"&_
"Password=myPassword"
oOleDbConnection=NewOleDb.OleDbConnection(sConnString)
oOleDbConnection.Open()
ForJETOLEDBProvider
'VB.NET
ImportsSystem.Data.OleDb
...
DimoOleDbConnectionAsOleDbConnection
DimsConnStringAsString=_
"Provider=Microsoft.Jet.OLEDB.4.0;"&_
"DataSource=C:
\myPath\myJet.mdb;"&_
"UserID=Admin;"&_
"Password="
oOleDbConnection=NewOleDb.OleDbConnection(sConnString)
oOleDbConnection.Open()
ForOracleOLEDBProvider
'VB.NET
ImportsSystem.Data.OleDb
...
DimoOleDbConnectionAsOleDbConnection
DimsConnStringAsString=_
"Provider=OraOLEDB.Oracle;"&_
"DataSource=MyOracleDB;"&_
"UserID=myUsername;"&_
"Password=myPassword"
oOleDbConnection=NewOleDb.OleDbConnection(sConnString)
oOleDbConnection.Open()
ForSQLServerOLEDBProvider
'VB.NET
ImportsSystem.Data.OleDb
...
DimoOleDbConnectionAsOleDbConnection
DimsConnStringAsString=_
"Provider=sqloledb;"&_
"DataSource=myServerName;"&_
"InitialCatalog=myDatabaseName;"&_
"UserId=myUsername;"&_
"Password=myPassword"
oOleDbConnection=NewOleDb.OleDbConnection(sConnString)
oOleDbConnection.Open()
ForSybaseASEOLEDBProvider
'VB.NET
ImportsSystem.Data.OleDb
...
DimoOleDbConnectionAsOleDbConnection
DimsConnStringAsString=_
"Provider=SybaseASEOLEDBProvider;"&_
"DataSource=MyDataSourceName;"&_
"ServerName=MyServerName;"&_
"Database=MyDatabaseName;"&_
"UserID=myUsername;"&_
"Password=myPassword"
oOleDbConnection=NewOleDb.OleDbConnection(sConnString)
oOleDbConnection.Open()
Oracle.NETDataProvider-FromMicrosoft
System.Data.OracleClient
TheOracle.NETFrameworkDataProviderisanadd-oncomponenttothe.NETFramework1.0,andisincludedinthe.NETFramework1.1.
TheOracle.NetdataproviderprovidesaccesstoanOracledatabaseusingtheOracleCallInterface(OCI)asprovidedbyOracleClientsoftware.
UsingC#:
usingSystem.Data.OracleClient;
OracleConnectionoOracleConn=newOracleConnection();
oOracleConn.ConnectionString="DataSource=Oracle8i;"+
"IntegratedSecurity=SSPI";
oOracleConn.Open();
UsingVB.NET:
ImportsSystem.Data.OracleClient
DimoOracleConnAsOracleConnection=NewOracleConnection()
oOracleConn.ConnectionString="DataSource=Oracle8i;"&_
"IntegratedSecurity=SSPI";
oOracleConn.Open()
Note:
YoumusthavetheOracle8iRelease3(8.1.7)Clientorlaterinstalledinorderforthisprovidertoworkcorrectly.
Note:
YoumusthavetheRTMversionofthe.NETFrameworkinstalledinorderforthisprovidertoworkcorrectly.
Note:
ThereareknownOracle7.3,Oracle8.0,andOracle9iclientandserverproblemsinthisbetarelease.Theserver-sideissuesshouldberesolvedinthefinalreleaseoftheproduct.However,Oracle7.3clientwillnotbesupported.
Oracle.NETDataProvider-FromOracle
Oracle.DataAccess.Client
TheOracle.NETFrameworkDataProviderfromOracleisanadd-oncomponenttothe.NETFramework.
UsingC#
usingOracle.DataAccess.Client;
...
OracleConnectionoOracleConn=newOracleConnection();
oOracleConn.ConnectionString="DataSource=MyOracleServerName;"+
"IntegratedSecurity=SSPI";
oOracleConn.Open();
UsingVB.NET
ImportsOracle.DataAccess.Client
...
DimoOracleConnAsOracleConnection=NewOracleConnection()
oOracleConn.ConnectionString="DataSource=MyOracleServerName;"&_
"IntegratedSecurity=SSPI";
oOracleConn.Open()
OraDirect.NETDataProvider-FromCoreLab
CoreLab.Oracle
TheOraDirect.NETDataProviderisanadd-oncomponenttothe.NET
FrameworkthatprovidesaccesstoanOracledatabaseusingtheOracle
CallInterface(OCI)asprovidedbyOracleClientsoftware.
UsingC#
usingCoreLab.Oracle;
OracleConnectionoOracleConn=newOracleConnection();
oOracleConn.ConnectionString="UserID=myUsername;"+
"Password=myPassword;"+
"Host=(local);"+
"Pooling=true;"+
"MinPoolSize=0;"+
"MaxPoolSize=100;"+
"ConnectionLifetime=0";
oOracleConn.Open();
UsingVB.NET
ImportsCoreLab.Oracle
DimoOracleConnAsOracleConnection=NewOracleConnection()
oOracleConn.ConnectionString="UserID=myUsername;"&_
"Password=myPassword;"&_
"Host=(local);"&_
"Pooling=true;"&_
"MinPoolSize=0;"&_
"MaxPoolSize=100;"&_
"ConnectionLifetime=0"
oOracleConn.Open()
MySQL.NETDataProvider
EID.MySqlClient
TheMySQL.NETNativeProviderisanadd-oncomponenttothe.NETFrameworkthatallowsyoutoaccesstheMySQLdatabasethrough
thenativeprotocol,withoutgoingthroughOLEDBorODBC.
UsingC#
usingEID.MySqlClient;
...
MySqlConnectionoMySqlConn=newMySqlConnection();
oMySqlConn.ConnectionString="DataSource=(local);"+
"Database=myDatabaseName;"+
"UserID=myUsername;"+
"Password=myPassword;"+
"CommandLogging=false";
oMySqlConn.Open();
UsingVB.NET
ImportsEID.MySqlClient
...
DimoMySqlConnAsMySqlConnection=NewMySqlConnection()
oMySqlConn.ConnectionString="DataSource=(local);"&_
"Database=myDatabaseName;"&_
"UserID=myUsername;"&_
"Password=myPassword;"&_
"CommandLogging=false"
oMySqlConn.Open()
PostgreSQLDirect.NETDataProvider
CoreLab.PostgreSql
ThePostgreSQLDirect.NETDataProviderisanadd-oncomponenttothe
.NETFrameworkthatallowsyoutoaccessthePostgreSQLdatabaseusing
nativemessage-basedprotocol,withoutgoingthroughOLEDBorODBC.
UsingC#
usingCoreLab.PostgreSql;
PgSqlConnectionoPgSqlConn=newPgSqlConnection();
oPgSqlConn.Co