Description:-
a connection
string is a string that specifies information about a data source and the means
of connecting to it. It is passed in code to an underlying driver or provider
in order to initiate the connection.
When your
application connects to a database or a data file you let ADO or ADO.Net
utilize a provider to do the job for you. The connection string contains the
information that the provider need to know to be able to establish a connection
to the database or the data file.
Because there are different
providers and each providers have multiple ways to make a connection there are
many different ways to write a connection string. It's like the address when
sending a regular mail. Depending on the origin and destination and who is
going to make the transport you need to write down the address in different
ways.
For example; the provider
needs the address to the server (or the path to the data file) to connect to.
This parameter is often named "Server" or "Data Source".
The value specified for this key in the connection string is passed on to the
provider and this is how it’s possible for the provider to know where to
connect.
There are some basic rules on
how to format the information needed for the connection to take place. The way
we represent the configuration values inside of the connection string. As it is
a string, there are no data types, it's all string values but they have to be
correctly coded so the drivers can read it properly.
Microsoft SQL Server
ODBC DSN
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Dsn=DsnName;" +
5. "Uid=UserName;" +
6. "Pwd=Secret;";
7. conn.Open();
ODBC -- Standard Connection
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Driver={SQL Server};"
+
5. "Server=DataBaseNamex;"
+
6. "DataBase=DataBaseName;"
+
7. "Uid=UserName;" +
8. "Pwd=Secret;";
9. conn.Open();
ODBC -- Trusted Connection
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Driver={SQL Server};"
+
5. "Server=ServerName;" +
6. "DataBase=DataBaseName;"
+
7. "Uid=;" +
8. "Pwd=;";
9. conn.Open();
10.// or
11.var conn = new OdbcConnection();
12.conn.ConnectionString =
13.
"Driver={SQL Server};" +
14.
"Server=ServerName;" +
15.
"DataBase=DataBaseName;" +
16.
"Trusted_Connection=Yes;";
17.conn.Open();
OleDb -- Standard Connection
1. using System.Data.OleDb;
2. var conn = new OleDbConnection();
3. conn.ConnectionString =
4. "Driver=SQLOLEDB;" +
5. "Data
Source=ServerName;" +
6. "Initial
Catalog=DataBaseName;" +
7. "User id=UserName;" +
8. "Password=Secret;";
9. conn.Open();
OleDb -- Trusted Connection
1. using System.Data.OleDb;
2. var conn = new OleDbConnection();
3. conn.ConnectionString =
4. "Driver=SQLOLEDB;" +
5. "Data
Source=ServerName;" +
6. "Initial
Catalog=DataBaseName;" +
7. "Integrated
Security=SSPI;";
8. conn.Open();
OleDb -- via IP Address
1. using System.Data.OleDb;
2. var conn = new OleDbConnection();
3. conn.ConnectionString =
4. "Driver=SQLOLEDB;" +
5. "Network
Library=DBMSSOCN;" +
6. "Data
Source=xxx.xxx.xxx.xxx,1433;" +
7. "Initial Catalog=DataBaseName;"
+
8. "User id=UserName;" +
9. "Password=Secret;";
10.conn.Open();
.NET DataProvider -- Standard Connection
1. using System.Data.SqlClient;
2. var conn = new SqlDbConnection();
3. conn.ConnectionString =
4. "Data
Source=ServerName;" +
5. "Initial
Catalog=DataBaseName;" +
6. "User id=UserName;" +
7. "Password=Secret;";
8. conn.Open();
.NET DataProvider -- Trusted Connection
1. using System.Data.SqlClient;
2. var conn = new SqlConnection();
3. conn.ConnectionString =
4. "Data
Source=ServerName;" +
5. "Initial
Catalog=DataBaseName;" +
6. "Integrated
Security=SSPI;";
7. conn.Open();
.NET DataProvider -- via IP Address
1. using System.Data.SqlClient;
2. var conn = new SqlConnection();
3. conn.ConnectionString =
4. "Network
Library=DBMSSOCN;" +
5. "Data
Source=xxx.xxx.xxx.xxx,1433;" +
6. "Initial
Catalog=DataBaseName;" +
7. "User Id=UserName;" +
8. "Password=Secret;";
9. conn.Open();
Microsoft Sql Express
.NET Data Provider -- Default Relative Path --
Standard Connection
1. using System.Data.SqlClient;
2. var conn = new SqlConnection();
3. conn.ConnectionString =
4. "Data Source=.\SQLExpress;" +
5. "User Instance=true;" +
6. "User Id=UserName;" +
7. "Password=Secret;" +
8. "AttachDbFilename=|DataDirectory|DataBaseName.mdf;"
9. conn.Open();
.NET Data Provider -- Default Relative Path --
Trusted Connection
1. using System.Data.SqlClient;
2. var conn = new SqlConnection();
3. conn.ConnectionString =
4. "Data Source=.\SQLExpress;" +
5. "User Instance=true;" +
6. "Integrated Security=true;" +
7. "AttachDbFilename=|DataDirectory|DataBaseName.mdf;"
8. conn.Open();
.NET Data Provider -- Custom Relative Path --
Standard Connection
1. using System.Data.SqlClient;
2. AppDomain.CurrentDomain.SetData(
3. "DataDirectory",
"C:\MyPath\");
4. var conn = new SqlConnection();
5. conn.ConnectionString =
6. "Data Source=.\SQLExpress;" +
7. "User Instance=true;" +
8. "User Id=UserName;" +
9. "Password=Secret;" +
10.
"AttachDbFilename=|DataDirectory|DataBaseName.mdf;"
11.conn.Open();
.NET Data Provider -- Custom Relative Path --
Trusted Connection
1. using System.Data.SqlClient;
2. AppDomain.CurrentDomain.SetData(
3. "DataDirectory",
"C:\MyPath\");
4. var conn = new SqlConnection();
5. conn.ConnectionString =
6. "Data Source=.\SQLExpress;" +
7. "User Instance=true;" +
8. "Integrated Security=true;" +
9. "AttachDbFilename=|DataDirectory|DataBaseName.mdf;"
10.conn.Open();
.NET Data Provider -- Absolute Path -- Standard
Connection
1. using System.Data.SqlClient;
2. var conn = new SqlConnection();
3. conn.ConnectionString =
4. "Data Source=.\SQLExpress;" +
5. "User Instance=true;" +
6. "User Id=UserName;" +
7. "Password=Secret;" +
8. "AttachDbFilename=C:\MyPath\DataBaseName.mdf;"
9. conn.Open();
.NET Data Provider -- Absolute Path -- Trusted
Connection
1. using System.Data.SqlClient;
2. var conn = new SqlConnection();
3. conn.ConnectionString =
4. "Data Source=.\SQLExpress;" +
5. "User Instance=true;" +
6. "Integrated Security=true;" +
7. "AttachDbFilename=C:\MyPath\DataBaseName.mdf;"
8. conn.Open();
Microsoft Access
ODBC DSN
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString = "Dsn=DsnName";
4. conn.Open();
ODBC -- Standard Security
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Driver={Microsoft Access Driver
(*.mdb)};" +
5. "Dbq=c:\myPath\myDb.mdb;" +
6. "Uid=Admin;Pwd=;";
7. conn.Open();
ODBC -- Workgroup (System Database)
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Driver={Microsoft Access Driver
(*.mdb)};" +
5. "Dbq=c:\myPath\myDb.mdb;" +
6. "SystemDb=c:\myPath\myDb.mdw;";
7. conn.Open();
ODBC -- Exclusive Use
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Driver={Microsoft Access Driver
(*.mdb)};" +
5. "Dbq=c:\myPath\myDb.mdb;" +
6. "Exclusive=1;";
7. "Uid=Admin;Pwd=;";
8. conn.Open();
OleDb with MS Jet -- Standard Security
1. using System.Data.OleDb;
2. var conn = new OleDbConnection();
3. conn.ConnectionString =
4. "Provider=Microsoft.Jet.OLEDB.4.0;"
+
5. "Data
Source=c:\mypath\myDb.mdb;" +
6. "User id=admin;" +
7. "Password=";
8. conn.Open();
OleDb with MS Jet -- Workgroup (System Database)
1. using System.Data.OleDb;
2. var conn = new OleDbConnection();
3. conn.ConnectionString =
4. "Provider=Microsoft.Jet.OLEDB.4.0;"
+
5. "Data
Source=c:\mypath\myDb.mdb;" +
6. "System
Database=c:\mypath\myDb.mdw;";
7. conn.Open();
OleDb with MS Jet -- With Password
1. using System.Data.OleDb;
2. var conn = new OleDbConnection();
3. conn.ConnectionString =
4. "Provider=Microsoft.Jet.OLEDB.4.0;"
+
5. "Data
Source=c:\mypath\myDb.mdb;" +
6. "Database
Password=Secret;"
7. conn.Open();
Oracle
ODBC DSN
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Dsn=DsnName;" +
5. "Uid=UserName;" +
6. "Pwd=Secret;";
7. conn.Open();
ODBC -- New Microsoft Driver
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Driver={Microsoft ODBC for
Oracle};" +
5. "Server=OracleServer.world;"
+
6. "Uid=UserName;" +
7. "Pwd=Secret;";
8. conn.Open();
ODBC -- Old Microsoft Driver
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Driver={Microsoft ODBC Driver for
Oracle};" +
5. "ConnectString=OracleServer.world;"
+
6. "Uid=UserName;" +
7. "Pwd=Secret;";
8. conn.Open();
ODBC -- Oracle Driver
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Driver={Oracle ODBC Driver};" +
5. "Dbq=myDataBase;" + // define in
tsnames.ora
6. "Uid=UserName;" +
7. "Pwd=Secret;";
8. conn.Open();
OleDb -- Microsoft Driver
1. uusing System.Data.OleDb;
2. var conn = new OleDbConnection();
3. conn.ConnectionString =
4. "Driver=MSDAORA;" +
5. "Data
Source=ServerName;" +
6. "User id=UserName;" +
7. "Password=Secret;";
8. conn.Open();
OleDb -- Oracle Driver -- Standard Connection
1. using System.Data.OleDb;
2. var conn = new OleDbConnection();
3. conn.ConnectionString =
4. "Driver=OraOLEDB.Oracle;"
+
5. "Data
Source=ServerName;" +
6. "User id=UserName;" +
7. "Password=Secret;";
8. conn.Open();
OleDb -- Oracle Driver -- Trusted Connection
1. using System.Data.OleDb;
2. var conn = new OleDbConnection();
3. conn.ConnectionString =
4. "Driver=OraOLEDB.Oracle;"
+
5. "Data
Source=ServerName;" +
6. "OSAuthent=1;";
7. conn.Open();
8. // or
9. using System.Data.OleDb;
10.var conn = new OleDbConnection();
11.conn.ConnectionString =
12.
"Driver=OraOLEDB.Oracle;" +
13.
"Data Source=ServerName;" +
14.
"User id=/" +
15.
"Password=;";
16.conn.Open();
.NET DataProvider from Microsoft -- Standard
Connection
1. using System.Data.OracleClient;
2. var conn = new OracleConnection();
3. conn.ConnectionString =
4. "Data
Source=ServerName;" +
5. "User id=UserName;";
6. "Password=Secret;";
7. conn.Open();
.NET DataProvider from Microsoft -- Trusted
Connection
1. using System.Data.OracleClient;
2. var conn = new OracleConnection();
3. conn.ConnectionString =
4. "Data
Source=Servername;" +
5. "Integrated
Security=Yes;";
6. conn.Open();
.NET DataProvider from Oracle -- Standard
Connection
1. using Oracle.DataAccess.Client;
2. var conn = new OracleConnection();
3. conn.ConnectionString =
4. "Data
Source=ServerName;" +
5. "User id=UserName;";
6. "Password=Secret;";
7. conn.Open();
.NET DataProvider from Oracle -- Trusted Connection
1. using Oracle.DataAccess.Client;
2. var conn = new OracleConnection();
3. conn.ConnectionString =
4. "Data
Source=Servername;" +
5. "Integrated
Security=Yes;";
6. conn.Open();
IBM DB2
ODBC DSN
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Dsn=DsnName;" +
5. "Uid=UserName;" +
6. "Pwd=Secret;";
7. conn.Open();
ODBC without DSN
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Driver={IBM DB2 ODBC
DRIVER};" +
5. "DataBase=DataBaseName;"
+
6. "HostName=ServerName;"
+
7. "Protocol=TCPIP;" +
8. "Port=PortNumber;" +
9. "Uid=UserName;" +
10.
"Pwd=Secret;";
11.conn.Open();
OleDb -- Microsoft Driver
1. using System.Data.OleDb;
2. var conn = new OleDbConnection();
3. conn.ConnectionString =
4. "Driver=DB2OLEDB;" +
5. "Network Transport
Library=TCPIP;" +
6. "Network
Address=xxx.xxx.xxx.xxx;" +
7. "Package
Collection=CollectionName;" +
8. "Initial
Catalog=DataBaseName;" +
9. "User id=UserName;" +
10.
"Password=Secret;";
11.conn.Open();
OleDb -- IBM Driver
1. using System.Data.OleDb;
2. var conn = new OleDbConnection();
3. conn.ConnectionString =
4. "Driver=IBMDADB2;" +
5. "DataBase=DataBaseName;"
+
6. "HostName=ServerName;" +
7. "Protocol=TCPIP;" +
8. "Port=PortNumber;" +
9. "Uid=UserName;" +
10.
"Pwd=Secret;";
11.conn.Open();
.NET DataProvider from IBM
1. using IBM.Data.DB2;
2. var conn = new Db2Connection();
3. conn.ConnectionString =
4. "DataBase=DataBaseName;"
+
5. "Uid=UserName;" +
6. "Pwd=Secret;" +
7. conn.Open();
MySql
ODBC DSN
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Dsn=DsnName;" +
5. "Uid=UserName;" +
6. "Pwd=Secret;";
7. conn.Open();
ODBC -- MyODBC Driver -- local database
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Driver={MySql};" +
5. "Server=localhost;" +
6. "Option=16834;" +
7. "DataBase=DataBaseName;"
8. conn.Open();
ODBC -- MyODBC Driver -- remote database
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Driver={MySql};" +
5. "Server=db.domain.com;" +
6. "Option=131072;" +
7. "Port=3306;" +
8. "Stmt=;" +
9. "DataBase=DataBaseName;"
+
10.
"Uid=UserName;" +
11.
"Pwd=Secret;"
12.conn.Open();
ODBC -- MySQL ODBC 3.51 Driver
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Driver={MySql ODBC 3.51
Driver};" +
5. "Server=ServerName;" +
6. "Option=16834;" +
7. "Port=3306;" +
8. "Stmt=;" +
9. "DataBase=DataBaseName;" +
10.
"Uid=UserName;" +
11.
"Pwd=Secret;"
12.conn.Open();
13.// or
14.var conn = new OdbcConnection();
15.conn.ConnectionString =
16.
"DRIVER={MySql ODBC 3.51 Driver};" +
17.
"SERVER=ServerName;" +
18.
"DATABASE=DataBaseName;" +
19.
"USER=UserName;" +
20.
"PASSWORD=Secret;"
21.conn.Open();
OleDb
1. using System.Data.OleDb;
2. var conn = new OleDbConnection();
3. conn.ConnectionString =
4. "Provider=MySqlProv;" +
5. "Data Source=ServerName;"
+
6. "User id=UserName;" +
7. "Password=Secret;"
8. conn.Open();
.NET DataProvider from CoreLab
1. using CoreLab.MySql;
2. var conn = new MySqlConnection();
3. conn.ConnectionString =
4. "Host=ServerName;" +
5. "DataBase=DataBaseName;"
+
6. "Protocol=TCP;" +
7. "Port=3306;" +
8. "Direct=true;" +
9. "Compress=false;" +
10.
"Pooling=true;" +
11.
"Min Pool Size=0;" +
12.
"Max Pool Size=100;" +
13.
"Connection Lifetime=0;" +
14. "User id=UserName;" +
15.
"Password=Secret;" +
16.conn.Open();
Sybase
ODBC DSN
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Dsn=DsnName;" +
5. "Uid=UserName;" +
6. "Pwd=Secret;";
7. conn.Open();
ODBC -- Sybase System 12 (12.5) ODBC Driver
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Driver={SYBASE ASE ODBC
Driver};" +
5. "Srvr=ServerName;" +
6. "Uid=UserName;" +
7. "Pwd=Secret;";
8. conn.Open();
ODBC -- Sybase System 11 ODBC Driver
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Driver={SYBASE SYSTEM
11};" +
5. "Srvr=ServerName;" +
6. "Uid=UserName;" +
7. "Pwd=Secret;";
8. conn.Open();
ODBC -- Intersolv 3.10 ODBC Driver
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Driver={INTERSOLV 3.10 32-BIT
Sybase};" +
5. "Srvr=ServerName;" +
6. "Uid=UserName;" +
7. "Pwd=Secret;";
8. conn.Open();
ODBC -- SQL Anywhere
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "ODBC;" +
5. "Driver={Sybase SQL Anywhere
5.0};" +
6. "DefaultDir=c:\myfolder\;" +
7. "Dbf=c:\mypath\dbname.db;" +
8. "Uid=UserName;" +
9. "Pwd=Secret;" +
10.
"Dsn="""";"; // Must be included!
11.conn.Open();
OleDb -- Sybase Adaptive Server Enterprise (ASE)
1. using System.Data.OleDb;
2. var conn = new OleDbConnection();
3. conn.ConnectionString =
4. "Driver=Sybase.ASEOLEDBProvider;"
+
5. "Server Name=ServerName,5000;" +
6. "Initial
Catalog=DataBaseName;" +
7. "User id=UserName;" +
8. "Password=Secret;";
9. conn.Open();
10.// optionally, replace
11.// 'Server Name' with 'Srvr', and
12.// 'Initial Catalog' with 'Catalog'
.NET DataProvider from Sybase
1. using Sybase.Data.AseClient;
2. var conn = new AseConnection();
3. conn.ConnectionString =
4. "Data
Source=ServerName;" +
5. "Initial
Catalog=DataBaseName;" +
6. "User id=UserName;" +
7. "Password=Secret;";
8. conn.Open();
Interbase
ODBC DSN
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Dsn=DsnName;" +
5. "Uid=UserName;" +
6. "Pwd=Secret;";
7. conn.Open();
ODBC -- EasySoft ODBC Driver -- local machine
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Driver={Easysoft IB6 ODBC};" +
5. "Server=localhost;" +
6. "DataBase=localhost:C:\MyPath\DbName.gdb;"
+
7. "Uid=UserName;" +
8. "Pwd=Secret;";
9. conn.Open();
ODBC -- EasySoft ODBC Driver -- remote machine
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Driver={Easysoft IB6 ODBC};" +
5. "Server=ServerName;" +
6. "DataBase=ServerName:C:\MyPath\DbName.gdb;"
+
7. "Uid=UserName;" +
8. "Pwd=Secret;";
9. conn.Open();
ODBC -- Intersolv ODBC Driver -- local machine
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Driver=" +
5. "{INTERSOLV InterBase ODBC Driver
(*.gdb)};" +
6. "Server=localhost;" +
7. "DataBase=localhost:C:\MyPath\DbName.gdb;"
+
8. "Uid=UserName;" +
9. "Pwd=Secret;";
10.conn.Open();
ODBC -- Intersolv ODBC Driver -- remote machine
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Driver=" +
5. "{INTERSOLV InterBase ODBC Driver
(*.gdb)};" +
6. "Server=ServerName;" +
7. "DataBase=ServerName:C:\MyPath\DbName.gdb;"
+
8. "Uid=UserName;" +
9. "Pwd=Secret;";
10.conn.Open();
Informix
ODBC DSN -- INFORMIX 3.30 ODBC Driver
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Dsn=DsnName;" +
5. "Host=HostName;" +
6. "Server=ServerName;" +
7. "Service=ServerName;" +
8. "Protocol=olsoctcp;" +
9. "Database=DataBaseName;"
+
10.
"Uid=UserName;" +
11.
"Pwd=Secret;";
12.conn.Open();
ODBC without DSN -- INFORMIX 3.30 ODBC Driver
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Dsn="";" +
5. "Driver={INFORMIX 3.30 32
BIT};" +
6. "Host=HostName;" +
7. "Server=ServerName;" +
8. "Service=ServerName;" +
9. "Protocol=olsoctcp;" +
10.
"Database=DataBaseName;" +
11.
"Uid=UserName;" +
12.
"Pwd=Secret;";
13.conn.Open();
ODBC Informix-CLI 2.5 ODBC Driver
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Driver={Informix-CLI 2.5 (32
Bit)};" +
5. "Server=ServerName;" +
6. "DataBase=DataBaseName;" +
7. "Uid=UserName;" +
8. "Pwd=Secret;";
9. conn.Open();
OleDb -- IBM Informix OleDb Provider
1. using System.Data.OleDb;
2. var conn = new OleDbConnection();
3. conn.ConnectionString =
4. "Driver=IFXOLEDBC;" +
5. "Data
Source=DataBaseName@ServerName;" +
6. "User id=UserName;" +
7. "Password=Secret;";
8. "Persist Security
Info=true;";
9. conn.Open();
Excel
ODBC DSN
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Dsn=DsnName;" +
5. "Uid=UserName;" +
6. "Pwd=Secret;";
7. conn.Open();
ODBC without DSN
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Driver={Microsoft Excel Driver
(*.xls)};" +
5. "Driverid=790;" +
6. "Dbq=C:\MyPath\SpreadSheet.xls;"
+
7. "DefaultDir=C:\MyPath;";
8. conn.Open();
OleDb with MS Jet
1. using System.Data.OleDb;
2. var conn = new OleDbConnection();
3. conn.ConnectionString =
4. "Driver=Microsoft.Jet.OLEDB.4.0;"
+
5. "Data
Source=C:\MyPath\SpreadSheet.xls;" +
6. @"Extended Properties=""Excel
8.0;HDR=Yes""";
7. conn.Open();
Text
ODBC DSN
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Dsn=DsnName;" +
5. "Uid=UserName;" +
6. "Pwd=Secret;";
7. conn.Open();
ODBC without DSN
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Driver={Microsoft Text Driver (*.txt;
*.csv)};" +
5. "Dbq=C:\MyPath\;" +
6. "Extensions=asc,csv,tab,txt;";
7. conn.Open();
8. // Use: sql = "Select * From
MyTextFile.txt"
OleDb with MS Jet
1. using System.Data.OleDb;
2. var conn = new OleDbConnection();
3. conn.ConnectionString =
4. "Driver=Microsoft.Jet.OLEDB.4.0;"
+
5. "Data Source=C:\MyPath\;" +
6. "Extended Properties=" +
7. @"""text;HDR=Yes;FMT=Delimited""";
8. conn.Open();
9. // Use: sql = "Select * From
MyTextFile.txt"
dBase Dbf
ODBC DSN
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString = "Dsn=DsnName";
4. conn.Open();
5. // Use: sql = "Select * From MyDb.dbf"
ODBC without DSN
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Driver={Microsoft dBASE Driver
(*.dbf)};" +
5. "Driverid=277;" +
6. "Dbq=C:\MyPath\";
7. conn.Open();
8. // Use: sql = "Select * From MyDb.dbf"
Visual FoxPro
ODBC DSN
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString = "Dsn=DsnName";
4. conn.Open();
ODBC without DSN -- Database container (dbc)
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Driver={Microsoft Visual FoxPro
Driver};" +
5. "SourceType=DBC;" +
6. "SourceDB=C:\MyPath\MyDb.dbc;"
+
7. "Exclusive=No";
8. conn.Open();
ODBC without DSN -- Free table directory
1. using System.Data.Odbc;
2. var conn = new OdbcConnection();
3. conn.ConnectionString =
4. "Driver={Microsoft Visual FoxPro
Driver};" +
5. "SourceType=DBF;" +
6. "SourceDB=C:\MyPath;" +
7. "Exclusive=No";
8. conn.Open();
OleDb -- Database container (dbc)
1. using System.Data.OleDb;
2. var conn = new OleDbConnection();
3. conn.ConnectionString =
4. "Driver=VFPOLEDB;" +
5. "Data
Source=C:\MyPath\MyDb.dbc;" +
6. "Collating
Sequence=machine;" +
7. "Password=Secret;";
8. conn.Open();
OleDb -- Free table directory
1. using System.Data.OleDb;
2. var conn = new OleDbConnection();
3. conn.ConnectionString =
4. "Driver=VFPOLEDB;" +
5. "Data
Source=C:\MyPath\;" +
6. "Collating
Sequence=general;" +
7. "Password=Secret;";
8. conn.Open();
Thanks for comments.....