使用DSN的数据库连接字符串例:
MS SQL / MySQL / PostgreSQL
"DSN=dsnname"
不使用DSN数据库连接字符串例:
MS Access
通过OLEDB:
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:somepathmyDb.mdb;"
MS SQL
通过ODBC:
"Driver={SQL Server}; Server=MyServerName; Database=myDatabaseName; UID=myUsername; PWD=myPassword"
With OLEDB (Recommended):
"Provider=sqloledb; Data Source=myServerName; Initial Catalog=myDatabaseName; User Id=myUsername; Password=myPassword"
MySQL
通过ODBC:
"Driver={MySQL ODBC 3.51 Driver}; Server=servername; Database=dbname; UID=username; PWD=password; Option=3"
PostgreSQL
通过ODBC:
"Driver={PostgreSQL}; Server=servername; Database=dbname; UID=username; PWD=password"
对于MS Access数据库来说,因为Access数据库的ODBC驱动程序会导致不稳定 ,所以最好不要通过DSN来连接。