Database Connection Strings
Database Connection Strings
Database Connection Strings
Code samples are in C#. You must provide the values in red
conn.ConnectionString =
"Dsn=DsnName;" +
"Uid=UserName;" +
"Pwd=Secret;";
conn.Open();
conn.ConnectionString =
"Driver={SQL Server};" +
"Server=DataBaseNamex;" +
"DataBase=DataBaseName;" +
"Uid=UserName;" +
"Pwd=Secret;";
conn.Open();
conn.ConnectionString =
"Driver={SQL Server};" +
"Server=ServerName;" +
"DataBase=DataBaseName;" +
"Uid=;" +
"Pwd=;";
conn.Open();
// or
conn.ConnectionString =
"Driver={SQL Server};" +
"Server=ServerName;" +
"DataBase=DataBaseName;" +
"Trusted_Connection=Yes;";
conn.Open();
conn.ConnectionString =
"Driver=SQLOLEDB;" +
"Data Source=ServerName;" +
"Initial Catalog=DataBaseName;" +
"User id=UserName;" +
"Password=Secret;";
conn.Open();
conn.ConnectionString =
"Driver=SQLOLEDB;" +
"Data Source=ServerName;" +
"Initial Catalog=DataBaseName;" +
"Integrated Security=SSPI;";
conn.Open();
OleDb via IP Address
using System.Data.OleDb;
conn.ConnectionString =
"Driver=SQLOLEDB;" +
"Network Library=DBMSSOCN;" +
"Data Source=xxx.xxx.xxx.xxx,1433;" +
"Initial Catalog=DataBaseName;" +
"User id=UserName;" +
"Password=Secret;";
conn.Open();
"Data Source=ServerName;" +
"Initial Catalog=DataBaseName;" +
"User id=UserName;" +
"Password=Secret;";
conn.Open();
conn.ConnectionString =
"Data Source=ServerName;" +
"Initial Catalog=DataBaseName;" +
"Integrated Security=SSPI;";
conn.Open();
conn.ConnectionString =
"Network Library=DBMSSOCN;" +
"Data Source=xxx.xxx.xxx.xxx,1433;" +
"Initial Catalog=DataBaseName;" +
"User Id=UserName;" +
"Password=Secret;";
conn.Open();
conn.ConnectionString =
"Data Source=.\SQLExpress;" +
"User Instance=true;" +
"User Id=UserName;" +
"Password=Secret;" +
"AttachDbFilename=|DataDirectory|DataBaseName.mdf;"
conn.Open();
conn.ConnectionString =
"Data Source=.\SQLExpress;" +
"User Instance=true;" +
"Integrated Security=true;" +
"AttachDbFilename=|DataDirectory|DataBaseName.mdf;"
conn.Open();
AppDomain.CurrentDomain.SetData(
"DataDirectory", "C:\MyPath\");
conn.ConnectionString =
"Data Source=.\SQLExpress;" +
"User Instance=true;" +
"User Id=UserName;" +
"Password=Secret;" +
"AttachDbFilename=|DataDirectory|DataBaseName.mdf;"
conn.Open();
AppDomain.CurrentDomain.SetData(
"DataDirectory", "C:\MyPath\");
var conn = new SqlConnection();
conn.ConnectionString =
"Data Source=.\SQLExpress;" +
"User Instance=true;" +
"Integrated Security=true;" +
"AttachDbFilename=|DataDirectory|DataBaseName.mdf;"
conn.Open();
conn.ConnectionString =
"Data Source=.\SQLExpress;" +
"User Instance=true;" +
"User Id=UserName;" +
"Password=Secret;" +
"AttachDbFilename=C:\MyPath\DataBaseName.mdf;"
conn.Open();
conn.ConnectionString =
"Data Source=.\SQLExpress;" +
"User Instance=true;" +
"Integrated Security=true;" +
"AttachDbFilename=C:\MyPath\DataBaseName.mdf;"
conn.Open();
Microsoft Access
ODBC DSN
using System.Data.Odbc;
conn.ConnectionString = "Dsn=DsnName";
conn.Open();
conn.ConnectionString =
"Uid=Admin;Pwd=;";
conn.Open();
conn.ConnectionString =
"Dbq=c:\myPath\myDb.mdb;" +
"SystemDb=c:\myPath\myDb.mdw;";
conn.Open();
"Dbq=c:\myPath\myDb.mdb;" +
"Exclusive=1;";
"Uid=Admin;Pwd=;";
conn.Open();
conn.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=c:\mypath\myDb.mdb;" +
"User id=admin;" +
"Password=";
conn.Open();
conn.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=c:\mypath\myDb.mdb;" +
"System Database=c:\mypath\myDb.mdw;";
conn.Open();
OleDb with MS Jet With Password
using System.Data.OleDb;
conn.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=c:\mypath\myDb.mdb;" +
"Database Password=Secret;"
conn.Open();
Oracle
ODBC DSN
using System.Data.Odbc;
conn.ConnectionString =
"Dsn=DsnName;" +
"Uid=UserName;" +
"Pwd=Secret;";
conn.Open();
conn.ConnectionString =
"Server=OracleServer.world;" +
"Uid=UserName;" +
"Pwd=Secret;";
conn.Open();
conn.ConnectionString =
"ConnectString=OracleServer.world;" +
"Uid=UserName;" +
"Pwd=Secret;";
conn.Open();
conn.ConnectionString =
"Uid=UserName;" +
"Pwd=Secret;";
conn.Open();
conn.ConnectionString =
"Driver=MSDAORA;" +
"Data Source=ServerName;" +
"User id=UserName;" +
"Password=Secret;";
conn.Open();
conn.ConnectionString =
"Driver=OraOLEDB.Oracle;" +
"Data Source=ServerName;" +
"User id=UserName;" +
"Password=Secret;";
conn.Open();
conn.ConnectionString =
"Driver=OraOLEDB.Oracle;" +
"Data Source=ServerName;" +
"OSAuthent=1;";
conn.Open();
// or
using System.Data.OleDb;
conn.ConnectionString =
"Driver=OraOLEDB.Oracle;" +
"Data Source=ServerName;" +
"User id=/" +
"Password=;";
conn.Open();
conn.ConnectionString =
"Data Source=ServerName;" +
"User id=UserName;";
"Password=Secret;";
conn.Open();
conn.ConnectionString =
"Data Source=Servername;" +
"Integrated Security=Yes;";
conn.Open();
conn.ConnectionString =
"Data Source=ServerName;" +
"User id=UserName;";
"Password=Secret;";
conn.Open();
conn.ConnectionString =
"Data Source=Servername;" +
"Integrated Security=Yes;";
conn.Open();
IBM DB2
ODBC DSN
using System.Data.Odbc;
conn.ConnectionString =
"Dsn=DsnName;" +
"Uid=UserName;" +
"Pwd=Secret;";
conn.Open();
conn.ConnectionString =
"DataBase=DataBaseName;" +
"HostName=ServerName;" +
"Protocol=TCPIP;" +
"Port=PortNumber;" +
"Uid=UserName;" +
"Pwd=Secret;";
conn.Open();
conn.ConnectionString =
"Driver=DB2OLEDB;" +
"Network Address=xxx.xxx.xxx.xxx;" +
"Package Collection=CollectionName;" +
"Initial Catalog=DataBaseName;" +
"User id=UserName;" +
"Password=Secret;";
conn.Open();
conn.ConnectionString =
"Driver=IBMDADB2;" +
"DataBase=DataBaseName;" +
"HostName=ServerName;" +
"Protocol=TCPIP;" +
"Port=PortNumber;" +
"Uid=UserName;" +
"Pwd=Secret;";
conn.Open();
conn.ConnectionString =
"DataBase=DataBaseName;" +
"Uid=UserName;" +
"Pwd=Secret;" +
conn.Open();
MySQL
ODBC DSN
using System.Data.Odbc;
conn.ConnectionString =
"Dsn=DsnName;" +
"Uid=UserName;" +
"Pwd=Secret;";
conn.Open();
conn.ConnectionString =
"Driver={MySql};" +
"Server=localhost;" +
"Option=16834;" +
"DataBase=DataBaseName;"
conn.Open();
conn.ConnectionString =
"Driver={MySql};" +
"Server=db.domain.com;" +
"Option=131072;" +
"Port=3306;" +
"Stmt=;" +
"DataBase=DataBaseName;" +
"Uid=UserName;" +
"Pwd=Secret;"
conn.Open();
conn.ConnectionString =
"Server=ServerName;" +
"Option=16834;" +
"Port=3306;" +
"Stmt=;" +
"DataBase=DataBaseName;" +
"Uid=UserName;" +
"Pwd=Secret;"
conn.Open();
// or
conn.ConnectionString =
"SERVER=ServerName;" +
"DATABASE=DataBaseName;" +
"USER=UserName;" +
"PASSWORD=Secret;"
conn.Open();
OleDb
using System.Data.OleDb;
conn.ConnectionString =
"Provider=MySqlProv;" +
"Data Source=ServerName;" +
"User id=UserName;" +
"Password=Secret;"
conn.Open();
.NET DataProvider from CoreLab
using CoreLab.MySql;
conn.ConnectionString =
"Host=ServerName;" +
"DataBase=DataBaseName;" +
"Protocol=TCP;" +
"Port=3306;" +
"Direct=true;" +
"Compress=false;" +
"Pooling=true;" +
"Connection Lifetime=0;" +
"User id=UserName;" +
"Password=Secret;" +
conn.Open();
Sybase
ODBC DSN
using System.Data.Odbc;
conn.ConnectionString =
"Dsn=DsnName;" +
"Uid=UserName;" +
"Pwd=Secret;";
conn.Open();
conn.ConnectionString =
"Srvr=ServerName;" +
"Uid=UserName;" +
"Pwd=Secret;";
conn.Open();
"Srvr=ServerName;" +
"Uid=UserName;" +
"Pwd=Secret;";
conn.Open();
conn.ConnectionString =
"Srvr=ServerName;" +
"Uid=UserName;" +
"Pwd=Secret;";
conn.Open();
conn.ConnectionString =
"ODBC;" +
"DefaultDir=c:\myfolder\;" +
"Dbf=c:\mypath\dbname.db;" +
"Uid=UserName;" +
"Pwd=Secret;" +
conn.Open();
conn.ConnectionString =
"Driver=Sybase.ASEOLEDBProvider;" +
"Server Name=ServerName,5000;" +
"Initial Catalog=DataBaseName;" +
"User id=UserName;" +
"Password=Secret;";
conn.Open();
// optionally, replace 'Server Name' with 'Srvr', and 'Initial Catalog' with 'Catalog'
.NET DataProvider from Sybase
using Sybase.Data.AseClient;
conn.ConnectionString =
"Data Source=ServerName;" +
"Initial Catalog=DataBaseName;" +
"User id=UserName;" +
"Password=Secret;";
conn.Open();
Interbase
ODBC DSN
using System.Data.Odbc;
conn.ConnectionString =
"Dsn=DsnName;" +
"Uid=UserName;" +
"Pwd=Secret;";
conn.Open();
conn.ConnectionString =
"Server=localhost;" +
"DataBase=localhost:C:\MyPath\DbName.gdb;" +
"Uid=UserName;" +
"Pwd=Secret;";
conn.Open();
conn.ConnectionString =
"Server=ServerName;" +
"DataBase=ServerName:C:\MyPath\DbName.gdb;" +
"Uid=UserName;" +
"Pwd=Secret;";
conn.Open();
conn.ConnectionString =
"Driver=" +
"Server=localhost;" +
"DataBase=localhost:C:\MyPath\DbName.gdb;" +
"Uid=UserName;" +
"Pwd=Secret;";
conn.Open();
conn.ConnectionString =
"Driver=" +
"Server=ServerName;" +
"DataBase=ServerName:C:\MyPath\DbName.gdb;" +
"Uid=UserName;" +
"Pwd=Secret;";
conn.Open();
Informix
ODBC DSN INFORMIX 3.30 ODBC Driver
using System.Data.Odbc;
conn.ConnectionString =
"Dsn=DsnName;" +
"Host=HostName;" +
"Server=ServerName;" +
"Service=ServerName;" +
"Protocol=olsoctcp;" +
"Database=DataBaseName;" +
"Uid=UserName;" +
"Pwd=Secret;";
conn.Open();
ODBC without DSN INFORMIX 3.30 ODBC Driver
using System.Data.Odbc;
conn.ConnectionString =
"Dsn="";" +
"Host=HostName;" +
"Server=ServerName;" +
"Service=ServerName;" +
"Protocol=olsoctcp;" +
"Database=DataBaseName;" +
"Uid=UserName;" +
"Pwd=Secret;";
conn.Open();
conn.ConnectionString =
"Server=ServerName;" +
"DataBase=DataBaseName;" +
"Uid=UserName;" +
"Pwd=Secret;";
9. conn.Open();
conn.ConnectionString =
"Driver=IFXOLEDBC;" +
"Data Source=DataBaseName@ServerName;" +
"User id=UserName;" +
"Password=Secret;";
conn.Open();
Excel
ODBC DSN
using System.Data.Odbc;
"Dsn=DsnName;" +
"Uid=UserName;" +
"Pwd=Secret;";
conn.Open();
conn.ConnectionString =
"Driverid=790;" +
"Dbq=C:\MyPath\SpreadSheet.xls;" +
"DefaultDir=C:\MyPath;";
conn.Open();
conn.ConnectionString =
"Driver=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=C:\MyPath\SpreadSheet.xls;" +
conn.Open();
Text
ODBC DSN
using System.Data.Odbc;
conn.ConnectionString =
"Dsn=DsnName;" +
"Uid=UserName;" +
"Pwd=Secret;";
conn.Open();
conn.ConnectionString =
"Dbq=C:\MyPath\;" +
"Extensions=asc,csv,tab,txt;";
conn.Open();
conn.ConnectionString =
"Driver=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=C:\MyPath\;" +
"Extended Properties=" +
@"""text;HDR=Yes;FMT=Delimited""";
conn.Open();
dBase Dbf
ODBC DSN
using System.Data.Odbc;
conn.ConnectionString = "Dsn=DsnName";
conn.Open();
conn.ConnectionString =
"Driverid=277;" +
"Dbq=C:\MyPath\";
conn.Open();
Visual FoxPro
ODBC DSN
using System.Data.Odbc;
conn.ConnectionString = "Dsn=DsnName";
conn.Open();
conn.ConnectionString =
"SourceType=DBC;" +
"SourceDB=C:\MyPath\MyDb.dbc;" +
"Exclusive=No";
conn.Open();
conn.ConnectionString =
"SourceType=DBF;" +
"SourceDB=C:\MyPath;" +
"Exclusive=No";
conn.Open();
conn.ConnectionString =
"Driver=VFPOLEDB;" +
"Data Source=C:\MyPath\MyDb.dbc;" +
"Collating Sequence=machine;" +
"Password=Secret;";
conn.Open();
conn.ConnectionString =
"Driver=VFPOLEDB;" +
"Data Source=C:\MyPath\;" +
"Collating Sequence=general;" +
"Password=Secret;";
conn.Open();
Host=192.168.10.10;
Server=db_engine_tcp;
Service=1492;
Protocol=onsoctcp;
UID=myUsername;
Password=myPassword;
Data Source=dbName@serverName;
User ID=myUsername;
Password=myPassword;
Data Source=dbName@serverName;
User ID=myUsername;
Password=myPassword;
OledbKey1=someValue;
OledbKey2=someValue;
See the respective OLEDB provider's connection strings options. The .net OleDbConnection will just pass on the
connection string to the specified OLEDB provider. Read more here.
Host=hostname;
Server=myServerAddress;
Service=service-name;
Protocol=olsoctcp;
Database=myDataBase;
Uid=myUsername;
Pwd=myPassword;
Informix-CLI 2.5
Informix-CLI 2.5:
Driver={Informix-CLI 2.5 (32 Bit)};
Server=myServerAddress;
Database=myDataBase;
Uid=myUsername;
Pwd=myPassword;
OdbcKey1=someValue;
OdbcKey2=someValue;
See the respective ODBC driver's connection strings options. The .net OdbcConnection will just pass on the
connection string to the specified ODBC driver. Read more here.
Client_Locale=en_us.8859-1;
Fet_Buf_Size=32767;
OptOFC=1;
AutoCommit=True;
BlobSize=-1;
WaitOnLocks=False;
CommitRetain=False;
IsolationLevel=ReadCommitted;
Trim Char=False;
money=currency;
decimal=bcd;
int8=fmtbcd;
lvarchar=string;
Standard dbExpress configuration parameters have higher priority against connection string parameters.