web-developer
HomeWindows/IISDHTMLRankingIndex ServerContact me 
 


 
DSN-Less Connections
mySQL:
Local database:
"Driver={mySQL};Server=mySrvName;Option=16834;Database=mydatabase;" 

 Remote database:
"Driver={mySQL};Server=data.domain.com;Port=3306;Option=131072;Stmt=;Database=my-database;Uid=username;Pwd=password;" 


Excel:
"Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=C:\MyExcel.xls;DefaultDir=c:\mypath;" 

Access:
Standard Security:
"Driver={Microsoft Access Driver (*.mdb)};Dbq=\somepath\mydb.mdb;Uid=Admin;Pwd=asdasd;" 


 Workgroup:
"Driver={Microsoft Access Driver (*.mdb)};Dbq=\somepath\mydb.mdb;SystemDB=\somepath\mydb.mdw;","admin", "" 

Oracle:
New version:
"Driver={Microsoft ODBC for Oracle};Server=OracleServer.world;Uid=Username;Pwd=asdasd;" 


 Old version:
"Driver={Microsoft ODBC Driver for Oracle};ConnectString=OracleServer.world;Uid=myUsername;Pwd=myPassword;" 


SQL Server:
 Standard Security:
"Driver={SQL Server};Server=Aron1;Database=pubs;Uid=sa;Pwd=asdasd;" 


 Trusted connection:
"Driver={SQL Server};Server=Aron1;Database=pubs;Trusted_Connection=yes;" 


 Prompt for username and password:
oConn.Properties("Prompt") = adPromptAlways
oConn.Open "Driver={SQL Server};Server=Aron1;DataBase=pubs;" 

 MS Data Shape
"Provider=MSDataShape;Data Provider=SQLOLEDB;Data Source=Aron1;Initial Catalog=pubs;User ID=sa;Password=asdasd;" 
 

Syntax for DSN-less Connection Strings

The following table lists the parameters to define and the syntax to use for each type of database in DSN-less connection strings.

Database Type

Syntax for DSN-less Connection Strings

DB2

connect_string = "Driver={DB2}; IP=[ip_address]; Port=[port_number]; Database=[database_name]; UID=[username]; PWD=[password]"

where [ip_address] is the IP address of the database server, [port_number] is the port for the database server, [database_name] is the name of the database, and [username] and [password] are the username and password required for accessing the database.

dBASE 5

connect_string = "Driver={Dbase}; DBQ=[pathname]; defaultDir=[default_directory]"

where [pathname] is the absolute path name of the directory containing the database file and [default_directory] is the default directory for the database.

Informix 7, 9

connect_string = "Driver={Informix}; ServerName=[server_name]; Database=[database_name]; UID=[username]; PWD=[password]"

where [server_name] is the name of the database server, [database_name] is the name of the database, and [username] and [password] are the username and password required for accessing the database.

Informix 2000

connect_string = "Driver={Informix}; HostName=[host_name]; ServerName=[server_name]; Port=[port_number];Database=[database_name]; UID=[username]; PWD=[password]"

where [host_name] is the name of the computer on which the database server resides, [server_name] is the name of the database server as it appears in the sqlhosts file, [port_number] is the port on which the database server is configured to listen, [database_name] is the name of the database, and [username] and [password] are the username and password required for accessing the database.

Microsoft Access

DSN-less connection strings and file DSNs are not supported for Microsoft Access databases. You must use system DSNs.

Microsoft SQL Server 6.5

DSN-less connection strings and file DSNs are not supported for Microsoft SQL Server 6.5 databases. You must use system DSNs.

Microsoft SQL Server 7.0 and 2000

connect_string = "Driver={SQL Server}; Database=[database_name]; Address=[ip_address],[port_number]; UID=[username]; PWD=[password]"

where [database_name] is the name of the database, [ip_address],[port_number] is the IP address of the database server and the port on which the database server is configured to listen, and [username] and [password] are the username and password required for accessing the database.

MySQL

connect_string = "Driver={Mysql}; Server=[server_name]; Database=[database_name]; UID=[username]; PWD=[password]"

where [server_name] is the name of the database server, [database_name] is the name of the database, and [username] and [password] are the username and password required for accessing the database.

Oracle 7, 8

connect_string = " Driver={Oracle}; Server=[TNS_name]; UID=[username]; PWD=[password]"

where [TNS_name] is the TNS name as defined in the tnsnames.ora file, and [username] and [password] are the username and password required for accessing the database.

Oracle 8i, 9i

connect_string = " Driver={Oracle}; Host=[host_name];Port=[port_number]; SID=[oracle_SID]; UID=[username]; PWD=[password]"

where [host_name] is the computer on which the database server resides, [port_number] is the port on which the database server is configured to listen, [oracle_SID] is the Oracle System Identifier that refers to the instance of Oracle running on the server, and [username] and [password] are the username and password required for accessing the database.

PostgreSQL

connect_string = " Driver={Postgres}; Server=[server_name]; Port=[port_number]; Database=[database_name]; UID=[username]; PWD=[password]"

where [server_name] is the name of the database server, [port_number] is the port on which the database server is configured to listen, [database_name] is the name of the database, and [username] and [password] are the username and password required for accessing the database.

Sybase

connect_string = " Driver={Sybase}; NetworkAddress=[host_name],[port_number]; Database=[database_name]; UID=[username]; PWD=[password]"

where [host_name],[port_number] is the IP address of the database server and the port on which the database server is configured to listen, [database_name] is the name of the database,; and [username] and [password] are the username and password required for accessing the database.

Text

connect_string = " Driver={Text}; Database=[database_location]"

where [database_location] is the directory in which the text files are stored.

See also:

============================
OLE DB Provider Connections
============================

OLE DB Provider for AS/400 
Conn.Open "Provider=IBMDA400; Data source=myAS400;" & _
                 "User Id=myUsername; Password=myPassword;"

 
 OLE DB Provider for Active Directory Service 
Conn.Open "Provider=ADSDSOObject; User Id=myUsername; Password=myPassword;"
 
 OLE DB Provider for DB2 
Conn.Open = "Provider=DB2OLEDB;" & _
                    "Network Transport Library=TCPIP; Network Address=MyServer;" & _
                    "Package Collection=MyPackage; Host CCSID=1142; Initial Catalog=MyDB;" & _
                    "User ID=MyUsername; Password=MyPassword;"

 
 OLE DB Provider for Index Server 
Conn.Open "Provider=msidxs; Data source=MyCatalog;"
 
 OLE DB Provider for Internet Publishing 
Conn.Open "Provider=MSDAIPP.DSO; Data Source=http://mywebsite/myDir;" & _
                 "User Id=myUsername; Password=myPassword;"

 
 OLE DB Provider for Microsoft Jet 
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\\somepath\\myDb.mdb;" & _
                 "User Id=admin; Password=;"

Using a Workgroup (System database)
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\\somepath\\mydb.mdb;" & _
                 "Jet OLEDB:System Database=MySystem.mdw;", "admin", ""

MDB has a database password
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\\somepath\\mydb.mdb;" & _
                 "Jet OLEDB:Database Password=MyDbPassword;", "admin", ""

Open Excel
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\\somepath\\Sheet1.xls;" & _
                 "Extended Properties=""Excel 8.0;HDR=Yes;"";"
 
 OLE DB Provider for ODBC Databases 
MS Access (Jet)
Conn.Open "Provider=MSDASQL; Driver={Microsoft Access Driver (*.mdb)};" & _
                 "Dbq=\\somepath\\mydb.mdb; Uid=myUsername; Pwd=myPassword;"

SQL Server
Conn.Open "Provider=MSDASQL; Driver={SQL Server};" & _
                 "Server=myServerName; Database=myDatabaseName;" & _
                 "Uid=myUsername; Pwd=myPassword;"

 
OLE DB Provider for Oracle 
from Microsoft
Conn.Open "Provider=msdaora; Data Source=MyOracleDB;" & _
                 "User Id=myUsername; Password=myPassword;"

from Oracle
Conn.Open "Provider=OraOLEDB.Oracle; Data Source=MyOracleDB;" & _
                 "User Id=myUsername; Password=myPassword;"

For a Trusted Connection
Conn.Open "Provider=OraOLEDB.Oracle; Data Source=MyOracleDB; User Id=/; Password=;"
Conn.Open "Provider=OraOLEDB.Oracle; Data Source=MyOracleDB; OSAuthent=1;"

 
 OLE DB Provider for Simple Provider 
Conn.Open "Provider=MSDAOSP; Data Source=MSXML2.DSOControl.2.6;"
rs.Open "http://WebServer/VirtualRoot/MyXMLFile.xml", Conn

 
 OLE DB Provider for SQL Server 
Conn.Open "Provider=sqloledb; Data Source=ServerName; Initial Catalog=DatabaseName;" & _
                 "User Id=myUsername; Password=myPassword;"

For a Trusted Connection
Conn.Open "Provider=sqloledb; Data Source=ServerName; Initial Catalog=DatabaseName;" & _
                 "Integrated Security=SSPI;"

Connect to a "Named Instance" (SQL Server 2000)
Conn.Open "Provider=sqloledb; Data Source=ServerName\\Inst2; Initial Catalog=DatabaseName;" & _
                 "User Id=myUsername; Password=myPassword;"

Prompt for username and password
Conn.Provider = "sqloledb"
Conn.Properties("Prompt") = adPromptAlways
Conn.Open "Data Source=ServerName; Initial Catalog=DatabaseName;"

To connect via an IP address
Conn.Open "Provider=sqloledb; Network Library=DBMSSOCN;" & _
                 "Data Source=xxx.xxx.xxx.xxx,1433; Initial Catalog=DatabaseName;" & _
                 "User ID=myUsername; Password=myPassword;"

 

==================================
Remote OLE DB Provider Connections
==================================

 MS Remote - Access (Jet) 
ODBC DSN
Conn.Open "Provider=MS Remote; Remote Server=http://ServerName; Remote Provider=MSDASQL; DSN=AdvWorks; Uid=myUsername; Pwd=myPassword;"

OLE DB Provider
Conn.Open "Provider=MS Remote; Remote Server=http://ServerName; Remote Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\\path\\mydb.mdb;", "admin", ""  

 MS Remote - SQL Server 

ODBC DSN
Conn.Open "Provider=MS Remote; Remote Server=http://server; Remote Provider=MSDASQL; DSN=DatabaseName; Uid=Username; Pwd=Password;"

OLE DB Provider
Conn.Open "Provider=MS Remote; Remote Server=http://ServerName; Remote Provider=SQLOLEDB; Data Source=ServerName; Initial Catalog=DatabaseName; User ID=Username; Password=Password;"  

=================================
.NET Managed Provider Connections
=================================

 SQL Client .NET Managed Provider (System.Data.SqlClient) 
Dim Conn As SqlClient.SqlConnection
Dim ConnStr As String

ConnStr = "Data Source=(local); Initial Catalog=NorthWind; Integrated Security=SSPI; Pooling=True; Min Pool Size=10; Max Pool Size=50; Connection Lifetime=30; Connection Reset=True; Enlist=True;"
Conn = New SqlClient.SqlConnection(ConnStr)
Conn.Open()  
 OLE DB .NET Managed Provider (System.Data.OleDb) 
Dim Conn As OleDb.OleDbConnection
Dim ConnStr As String

ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=nwind.mdb; User ID=Admin; Password=;"
Conn = New OleDb.OleDbConnection(ConnStr)
Conn.Open()  
====================
ODBC DNS Connections
=====================

DNS 
Conn.Open "DSN=SampleDB;Uid=Admin;Pwd=;"
 
File DNS 
Conn.Open "FILEDSN=\\path\\mydb.dsn;Uid=Admin;Pwd=;"
 

ODBC DNS-Less Connections
ODBC Driver for AS/400 
Conn.Open "Driver={Client Access ODBC Driver (32-bit)}; System=myAS400;Uid=myUsername;Pwd=myPassword;"

 
ODBC Driver for dBASE 
Conn.Open "Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=\\somepath;"
rs.Open "SELECT * FROM USER.DBF", Conn

 
ODBC Driver for MS Access 
Conn.Open "Driver={Microsoft Access Driver (*.mdb)};" & _
                 "Dbq=\\path\\mydb.mdb;Uid=Admin;Pwd=;"

Using a Workgroup (System database)
Conn.Open "Driver={Microsoft Access Driver (*.mdb)};" & _
                "Dbq=\\path\\mydb.mdb;SystemDB=\\somepath\\mydb.mdw;", "admin",""
 
ODBC Driver for MS Excel 
Conn.Open "Driver={Microsoft Excel Driver (*.xls)};DriverId=790;" & _
                 "Dbq=\\somepath\\Sheet1.xls;DefaultDir=\\somepath;"


ODBC Driver for MySQL (MyODBC) 
Conn.Open "Driver={mySQL};Server=MyServerName;Option=16834;Database=mydb;"
 
ODBC Driver for Oracle 
Conn.Open "Driver={Microsoft ODBC for Oracle};Server=OracleServer.world;" & _
                 "Uid=myUsername;Pwd=myPassword;"

 
ODBC Driver for Paradox 
Conn.Open "Driver={Microsoft Paradox Driver (*.db)};DriverID=538;Fil=Paradox 5.X;" & _
                 "DefaultDir=c:\\dbpath\\;Dbq=c:\\dbpath\\;CollatingSequence=ASCII;"

 
ODBC Driver for SQL Server 
Conn.Open "Driver={SQL Server};Server=MyServerName;Database=myDatabaseName;" & _
                 "Uid=myUsername;Pwd=myPassword

For trusted connection
Conn.Open "Driver={SQL Server};Server=MyServerName;Database=myDatabaseName;" & _
                 "Trusted_Connection=yes;"

To Prompt user for username and password
Conn.Properties("Prompt") = adPromptAlways
Conn.Open "Driver={SQL Server}; Server=ServerName; DataBase=DatabaseName;"

 
ODBC Driver for Sybase 
Sybase System 11 ODBC Driver
Conn.Open "Driver={SYBASE SYSTEM 11}; Srvr=myServerName;" & _
                 "Uid=myUsername; Pwd=myPassword;"

Intersolv 3.10 Sybase ODBC Driver
Conn.Open "Driver={INTERSOLV 3.10 32-BIT Sybase}; Srvr=myServerName;" & _
                 "Uid=myUsername; Pwd=myPassword;"

 
ODBC Driver for Sybase SQL Anywhere 
Conn.Open "ODBC; Driver=Sybase SQL Anywhere 5.0;" & _
                 "DefaultDir=c:\\dbpath\\; Dbf=c:\\sqlany50\\mydb.db;" & _
                 "Uid=myUsername; Pwd=myPassword; Dsn="""";"

 
ODBC Driver for Text 
Conn.Open "Driver={Microsoft Text Driver (*.txt; *.csv)};" & _
                 "Dbq=\\somepath\\; Extensions=asc,csv,tab,txt; Persist Security Info=False"
rs.Open "SELECT * FROM CUSTOMER.CSV", Conn

 
ODBC Driver for Visual FoxPro 
With a database container
Conn.Open "Driver={Microsoft Visual FoxPro Driver}; SourceType=DBC;" & _
                 "SourceDB=\\somepath\\mySourceDb.dbc; Exclusive=No;"

Without a database container (Free Table Directory)
Conn.Open "Driver={Microsoft Visual FoxPro Driver}; SourceType=DBF;" & _
                 "SourceDB=\\somepath\\mySourceDbFolder; Exclusive=No;"