c# Database Connectionstrings

Microsoft SQL Server


ODBC DSN
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Dsn=DsnName;" +
  6. "Uid=UserName;" +
  7. "Pwd=Secret;";
  8. conn.Open();


ODBC -- Standard Connection
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Driver={SQL Server};" +
  6. "Server=DataBaseNamex;" +
  7. "DataBase=DataBaseName;" +
  8. "Uid=UserName;" +
  9. "Pwd=Secret;";
  10. conn.Open();


ODBC -- Trusted Connection
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Driver={SQL Server};" +
  6. "Server=ServerName;" +
  7. "DataBase=DataBaseName;" +
  8. "Uid=;" +
  9. "Pwd=;";
  10. conn.Open();
  11.  
  12. // or
  13.  
  14. var conn = new OdbcConnection();
  15. conn.ConnectionString =
  16. "Driver={SQL Server};" +
  17. "Server=ServerName;" +
  18. "DataBase=DataBaseName;" +
  19. "Trusted_Connection=Yes;";
  20. conn.Open();


OleDb -- Standard Connection
  
  
  1. using System.Data.OleDb;
  2.  
  3. var conn = new OleDbConnection();
  4. conn.ConnectionString =
  5. "Driver=SQLOLEDB;" +
  6. "Data Source=ServerName;" +
  7. "Initial Catalog=DataBaseName;" +
  8. "User id=UserName;" +
  9. "Password=Secret;";
  10. conn.Open();


OleDb -- Trusted Connection
  
  
  1. using System.Data.OleDb;
  2.  
  3. var conn = new OleDbConnection();
  4. conn.ConnectionString =
  5. "Driver=SQLOLEDB;" +
  6. "Data Source=ServerName;" +
  7. "Initial Catalog=DataBaseName;" +
  8. "Integrated Security=SSPI;";
  9. conn.Open();


OleDb -- via IP Address
  
  
  1. using System.Data.OleDb;
  2.  
  3. var conn = new OleDbConnection();
  4. conn.ConnectionString =
  5. "Driver=SQLOLEDB;" +
  6. "Network Library=DBMSSOCN;" +
  7. "Data Source=xxx.xxx.xxx.xxx,1433;" +
  8. "Initial Catalog=DataBaseName;" +
  9. "User id=UserName;" +
  10. "Password=Secret;";
  11. conn.Open();


.NET DataProvider -- Standard Connection
  
  
  1. using System.Data.SqlClient;
  2.  
  3. var conn = new SqlDbConnection();
  4. conn.ConnectionString =
  5. "Data Source=ServerName;" +
  6. "Initial Catalog=DataBaseName;" +
  7. "User id=UserName;" +
  8. "Password=Secret;";
  9. conn.Open();


.NET DataProvider -- Trusted Connection
  
  
  1. using System.Data.SqlClient;
  2.  
  3. var conn = new SqlConnection();
  4. conn.ConnectionString =
  5. "Data Source=ServerName;" +
  6. "Initial Catalog=DataBaseName;" +
  7. "Integrated Security=SSPI;";
  8. conn.Open();


.NET DataProvider -- via IP Address
  
  
  1. using System.Data.SqlClient;
  2.  
  3. var conn = new SqlConnection();
  4. conn.ConnectionString =
  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();





Microsoft Sql Express



.NET Data Provider -- Default Relative Path -- Standard Connection
  
  
  1. using System.Data.SqlClient;
  2.  
  3. var conn = new SqlConnection();
  4. conn.ConnectionString =
  5. "Data Source=.\SQLExpress;" +
  6. "User Instance=true;" +
  7. "User Id=UserName;" +
  8. "Password=Secret;" +
  9. "AttachDbFilename=|DataDirectory|DataBaseName.mdf;"
  10. conn.Open();


.NET Data Provider -- Default Relative Path -- Trusted Connection
  
  
  1. using System.Data.SqlClient;
  2.  
  3. var conn = new SqlConnection();
  4. conn.ConnectionString =
  5. "Data Source=.\SQLExpress;" +
  6. "User Instance=true;" +
  7. "Integrated Security=true;" +
  8. "AttachDbFilename=|DataDirectory|DataBaseName.mdf;"
  9. conn.Open();


.NET Data Provider -- Custom Relative Path -- Standard Connection
  
  
  1. using System.Data.SqlClient;
  2.  
  3. AppDomain.CurrentDomain.SetData("DataDirectory", "C:\MyPath\");
  4.  
  5. var conn = new SqlConnection();
  6. conn.ConnectionString =
  7. "Data Source=.\SQLExpress;" +
  8. "User Instance=true;" +
  9. "User Id=UserName;" +
  10. "Password=Secret;" +
  11. "AttachDbFilename=|DataDirectory|DataBaseName.mdf;"
  12. conn.Open();


.NET Data Provider -- Custom Relative Path -- Trusted Connection
  
  
  1. using System.Data.SqlClient;
  2.  
  3. AppDomain.CurrentDomain.SetData(
  4. "DataDirectory", "C:\MyPath\");
  5.  
  6. var conn = new SqlConnection();
  7. conn.ConnectionString =
  8. "Data Source=.\SQLExpress;" +
  9. "User Instance=true;" +
  10. "Integrated Security=true;" +
  11. "AttachDbFilename=|DataDirectory|DataBaseName.mdf;"
  12. conn.Open();


.NET Data Provider -- Absolute Path -- Standard Connection
  
  
  1. using System.Data.SqlClient;
  2.  
  3. var conn = new SqlConnection();
  4. conn.ConnectionString =
  5. "Data Source=.\SQLExpress;" +
  6. "User Instance=true;" +
  7. "User Id=UserName;" +
  8. "Password=Secret;" +
  9. "AttachDbFilename=C:\MyPath\DataBaseName.mdf;"
  10. conn.Open();


.NET Data Provider -- Absolute Path -- Trusted Connection
  
  
  1. using System.Data.SqlClient;
  2.  
  3. var conn = new SqlConnection();
  4. conn.ConnectionString =
  5. "Data Source=.\SQLExpress;" +
  6. "User Instance=true;" +
  7. "Integrated Security=true;" +
  8. "AttachDbFilename=C:\MyPath\DataBaseName.mdf;"
  9. conn.Open();





Microsoft Access



ODBC DSN
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString = "Dsn=DsnName";
  5. conn.Open();


ODBC -- Standard Security
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Driver={Microsoft Access Driver (*.mdb)};" +
  6. "Dbq=c:\myPath\myDb.mdb;" +
  7. "Uid=Admin;Pwd=;";
  8. conn.Open();


ODBC -- Workgroup (System Database)
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Driver={Microsoft Access Driver (*.mdb)};" +
  6. "Dbq=c:\myPath\myDb.mdb;" +
  7. "SystemDb=c:\myPath\myDb.mdw;";
  8. conn.Open();


ODBC -- Exclusive Use
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Driver={Microsoft Access Driver (*.mdb)};" +
  6. "Dbq=c:\myPath\myDb.mdb;" +
  7. "Exclusive=1;";
  8. "Uid=Admin;Pwd=;";
  9. conn.Open();


OleDb with MS Jet -- Standard Security
  
  
  1. using System.Data.OleDb;
  2.  
  3. var conn = new OleDbConnection();
  4. conn.ConnectionString =
  5. "Provider=Microsoft.Jet.OLEDB.4.0;" +
  6. "Data Source=c:\mypath\myDb.mdb;" +
  7. "User id=admin;" +
  8. "Password=";
  9. conn.Open();


OleDb with MS Jet -- Workgroup (System Database)
  
  
  1. using System.Data.OleDb;
  2.  
  3. var conn = new OleDbConnection();
  4. conn.ConnectionString =
  5. "Provider=Microsoft.Jet.OLEDB.4.0;" +
  6. "Data Source=c:\mypath\myDb.mdb;" +
  7. "System Database=c:\mypath\myDb.mdw;";
  8. conn.Open();


OleDb with MS Jet -- With Password
  
  
  1. using System.Data.OleDb;
  2.  
  3. var conn = new OleDbConnection();
  4. conn.ConnectionString =
  5. "Provider=Microsoft.Jet.OLEDB.4.0;" +
  6. "Data Source=c:\mypath\myDb.mdb;" +
  7. "Database Password=Secret;"
  8. conn.Open();





Oracle



ODBC DSN
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Dsn=DsnName;" +
  6. "Uid=UserName;" +
  7. "Pwd=Secret;";
  8. conn.Open();


ODBC -- New Microsoft Driver
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Driver={Microsoft ODBC for Oracle};" +
  6. "Server=OracleServer.world;" +
  7. "Uid=UserName;" +
  8. "Pwd=Secret;";
  9. conn.Open();


ODBC -- Old Microsoft Driver
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Driver={Microsoft ODBC Driver for Oracle};" +
  6. "ConnectString=OracleServer.world;" +
  7. "Uid=UserName;" +
  8. "Pwd=Secret;";
  9. conn.Open();


ODBC -- Oracle Driver
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Driver={Oracle ODBC Driver};" +
  6. "Dbq=myDataBase;" + // define in tsnames.ora
  7. "Uid=UserName;" +
  8. "Pwd=Secret;";
  9. conn.Open();


OleDb -- Microsoft Driver
  
  
  1. uusing System.Data.OleDb;
  2.  
  3. var conn = new OleDbConnection();
  4. conn.ConnectionString =
  5. "Driver=MSDAORA;" +
  6. "Data Source=ServerName;" +
  7. "User id=UserName;" +
  8. "Password=Secret;";
  9. conn.Open();


OleDb -- Oracle Driver -- Standard Connection
  
  
  1. using System.Data.OleDb;
  2.  
  3. var conn = new OleDbConnection();
  4. conn.ConnectionString =
  5. "Driver=OraOLEDB.Oracle;" +
  6. "Data Source=ServerName;" +
  7. "User id=UserName;" +
  8. "Password=Secret;";
  9. conn.Open();


OleDb -- Oracle Driver -- Trusted Connection
  
  
  1. using System.Data.OleDb;
  2.  
  3. var conn = new OleDbConnection();
  4. conn.ConnectionString =
  5. "Driver=OraOLEDB.Oracle;" +
  6. "Data Source=ServerName;" +
  7. "OSAuthent=1;";
  8. conn.Open();
  9.  
  10. // or
  11.  
  12. using System.Data.OleDb;
  13. var conn = new OleDbConnection();
  14. conn.ConnectionString =
  15. "Driver=OraOLEDB.Oracle;" +
  16. "Data Source=ServerName;" +
  17. "User id=/" +
  18. "Password=;";
  19. conn.Open();


.NET DataProvider from Microsoft -- Standard Connection
  
  
  1. using System.Data.OracleClient;
  2.  
  3. var conn = new OracleConnection();
  4. conn.ConnectionString =
  5. "Data Source=ServerName;" +
  6. "User id=UserName;";
  7. "Password=Secret;";
  8. conn.Open();


.NET DataProvider from Microsoft -- Trusted Connection
  
  
  1. using System.Data.OracleClient;
  2.  
  3. var conn = new OracleConnection();
  4. conn.ConnectionString =
  5. "Data Source=Servername;" +
  6. "Integrated Security=Yes;";
  7. conn.Open();


.NET DataProvider from Oracle -- Standard Connection
  
  
  1. using Oracle.DataAccess.Client;
  2.  
  3. var conn = new OracleConnection();
  4. conn.ConnectionString =
  5. "Data Source=ServerName;" +
  6. "User id=UserName;";
  7. "Password=Secret;";
  8. conn.Open();


.NET DataProvider from Oracle -- Trusted Connection
  
  
  1. using Oracle.DataAccess.Client;
  2.  
  3. var conn = new OracleConnection();
  4. conn.ConnectionString =
  5. "Data Source=Servername;" +
  6. "Integrated Security=Yes;";
  7. conn.Open();





IBM DB2



ODBC DSN
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Dsn=DsnName;" +
  6. "Uid=UserName;" +
  7. "Pwd=Secret;";
  8. conn.Open();


ODBC without DSN
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Driver={IBM DB2 ODBC DRIVER};" +
  6. "DataBase=DataBaseName;" +
  7. "HostName=ServerName;" +
  8. "Protocol=TCPIP;" +
  9. "Port=PortNumber;" +
  10. "Uid=UserName;" +
  11. "Pwd=Secret;";
  12. conn.Open();


OleDb -- Microsoft Driver
  
  
  1. using System.Data.OleDb;
  2.  
  3. var conn = new OleDbConnection();
  4. conn.ConnectionString =
  5. "Driver=DB2OLEDB;" +
  6. "Network Transport Library=TCPIP;" +
  7. "Network Address=xxx.xxx.xxx.xxx;" +
  8. "Package Collection=CollectionName;" +
  9. "Initial Catalog=DataBaseName;" +
  10. "User id=UserName;" +
  11. "Password=Secret;";
  12. conn.Open();


OleDb -- IBM Driver
  
  
  1. using System.Data.OleDb;
  2.  
  3. var conn = new OleDbConnection();
  4. conn.ConnectionString =
  5. "Driver=IBMDADB2;" +
  6. "DataBase=DataBaseName;" +
  7. "HostName=ServerName;" +
  8. "Protocol=TCPIP;" +
  9. "Port=PortNumber;" +
  10. "Uid=UserName;" +
  11. "Pwd=Secret;";
  12. conn.Open();


.NET DataProvider from IBM
  
  
  1. using IBM.Data.DB2;
  2.  
  3. var conn = new Db2Connection();
  4. conn.ConnectionString =
  5. "DataBase=DataBaseName;" +
  6. "Uid=UserName;" +
  7. "Pwd=Secret;" +
  8. conn.Open();





MySql



ODBC DSN
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Dsn=DsnName;" +
  6. "Uid=UserName;" +
  7. "Pwd=Secret;";
  8. conn.Open();


ODBC -- MyODBC Driver -- local database
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Driver={MySql};" +
  6. "Server=localhost;" +
  7. "Option=16834;" +
  8. "DataBase=DataBaseName;"
  9. conn.Open();


ODBC -- MyODBC Driver -- remote database
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Driver={MySql};" +
  6. "Server=db.domain.com;" +
  7. "Option=131072;" +
  8. "Port=3306;" +
  9. "Stmt=;" +
  10. "DataBase=DataBaseName;" +
  11. "Uid=UserName;" +
  12. "Pwd=Secret;"
  13. conn.Open();


ODBC -- MySQL ODBC 3.51 Driver
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Driver={MySql ODBC 3.51 Driver};" +
  6. "Server=ServerName;" +
  7. "Option=16834;" +
  8. "Port=3306;" +
  9. "Stmt=;" +
  10. "DataBase=DataBaseName;" +
  11. "Uid=UserName;" +
  12. "Pwd=Secret;"
  13. conn.Open();
  14.  
  15. // or
  16.  
  17. var conn = new OdbcConnection();
  18. conn.ConnectionString =
  19. "DRIVER={MySql ODBC 3.51 Driver};" +
  20. "SERVER=ServerName;" +
  21. "DATABASE=DataBaseName;" +
  22. "USER=UserName;" +
  23. "PASSWORD=Secret;"
  24. conn.Open();


OleDb
  
  
  1. using System.Data.OleDb;
  2.  
  3. var conn = new OleDbConnection();
  4. conn.ConnectionString =
  5. "Provider=MySqlProv;" +
  6. "Data Source=ServerName;" +
  7. "User id=UserName;" +
  8. "Password=Secret;"
  9. conn.Open();


.NET DataProvider from CoreLab
  
  
  1. using CoreLab.MySql;
  2.  
  3. var conn = new MySqlConnection();
  4. conn.ConnectionString =
  5. "Host=ServerName;" +
  6. "DataBase=DataBaseName;" +
  7. "Protocol=TCP;" +
  8. "Port=3306;" +
  9. "Direct=true;" +
  10. "Compress=false;" +
  11. "Pooling=true;" +
  12. "Min Pool Size=0;" +
  13. "Max Pool Size=100;" +
  14. "Connection Lifetime=0;" +
  15. "User id=UserName;" +
  16. "Password=Secret;" +
  17. conn.Open();





Sybase



ODBC DSN
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Dsn=DsnName;" +
  6. "Uid=UserName;" +
  7. "Pwd=Secret;";
  8. conn.Open();


ODBC -- Sybase System 12 (12.5) ODBC Driver
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Driver={SYBASE ASE ODBC Driver};" +
  6. "Srvr=ServerName;" +
  7. "Uid=UserName;" +
  8. "Pwd=Secret;";
  9. conn.Open();


ODBC -- Sybase System 11 ODBC Driver
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Driver={SYBASE SYSTEM 11};" +
  6. "Srvr=ServerName;" +
  7. "Uid=UserName;" +
  8. "Pwd=Secret;";
  9. conn.Open();


ODBC -- Intersolv 3.10 ODBC Driver
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Driver={INTERSOLV 3.10 32-BIT Sybase};" +
  6. "Srvr=ServerName;" +
  7. "Uid=UserName;" +
  8. "Pwd=Secret;";
  9. conn.Open();


ODBC -- SQL Anywhere
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "ODBC;" +
  6. "Driver={Sybase SQL Anywhere 5.0};" +
  7. "DefaultDir=c:\myfolder\;" +
  8. "Dbf=c:\mypath\dbname.db;" +
  9. "Uid=UserName;" +
  10. "Pwd=Secret;" +
  11. "Dsn="""";"; // Must be included!
  12. conn.Open();


OleDb -- Sybase Adaptive Server Enterprise (ASE)
  
  
  1. using System.Data.OleDb;
  2.  
  3. var conn = new OleDbConnection();
  4. conn.ConnectionString =
  5. "Driver=Sybase.ASEOLEDBProvider;" +
  6. "Server Name=ServerName,5000;" +
  7. "Initial Catalog=DataBaseName;" +
  8. "User id=UserName;" +
  9. "Password=Secret;";
  10. conn.Open();
  11. // optionally, replace
  12. // 'Server Name' with 'Srvr', and
  13. // 'Initial Catalog' with 'Catalog'


.NET DataProvider from Sybase
  
  
  1. using Sybase.Data.AseClient;
  2.  
  3. var conn = new AseConnection();
  4. conn.ConnectionString =
  5. "Data Source=ServerName;" +
  6. "Initial Catalog=DataBaseName;" +
  7. "User id=UserName;" +
  8. "Password=Secret;";
  9. conn.Open();





Interbase



ODBC DSN
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Dsn=DsnName;" +
  6. "Uid=UserName;" +
  7. "Pwd=Secret;";
  8. conn.Open();


ODBC -- EasySoft ODBC Driver -- local machine
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Driver={Easysoft IB6 ODBC};" +
  6. "Server=localhost;" +
  7. "DataBase=localhost:C:\MyPath\DbName.gdb;" +
  8. "Uid=UserName;" +
  9. "Pwd=Secret;";
  10. conn.Open();


ODBC -- EasySoft ODBC Driver -- remote machine
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Driver={Easysoft IB6 ODBC};" +
  6. "Server=ServerName;" +
  7. "DataBase=ServerName:C:\MyPath\DbName.gdb;" +
  8. "Uid=UserName;" +
  9. "Pwd=Secret;";
  10. conn.Open();


ODBC -- Intersolv ODBC Driver -- local machine
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Driver=" +
  6. "{INTERSOLV InterBase ODBC Driver (*.gdb)};" +
  7. "Server=localhost;" +
  8. "DataBase=localhost:C:\MyPath\DbName.gdb;" +
  9. "Uid=UserName;" +
  10. "Pwd=Secret;";
  11. conn.Open();


ODBC -- Intersolv ODBC Driver -- remote machine
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Driver=" +
  6. "{INTERSOLV InterBase ODBC Driver (*.gdb)};" +
  7. "Server=ServerName;" +
  8. "DataBase=ServerName:C:\MyPath\DbName.gdb;" +
  9. "Uid=UserName;" +
  10. "Pwd=Secret;";
  11. conn.Open();





Informix



ODBC DSN -- INFORMIX 3.30 ODBC Driver
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Dsn=DsnName;" +
  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 without DSN -- INFORMIX 3.30 ODBC Driver
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Dsn="";" +
  6. "Driver={INFORMIX 3.30 32 BIT};" +
  7. "Host=HostName;" +
  8. "Server=ServerName;" +
  9. "Service=ServerName;" +
  10. "Protocol=olsoctcp;" +
  11. "Database=DataBaseName;" +
  12. "Uid=UserName;" +
  13. "Pwd=Secret;";
  14. conn.Open();


ODBC Informix-CLI 2.5 ODBC Driver
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Driver={Informix-CLI 2.5 (32 Bit)};" +
  6. "Server=ServerName;" +
  7. "DataBase=DataBaseName;" +
  8. "Uid=UserName;" +
  9. "Pwd=Secret;";
  10. conn.Open();


OleDb -- IBM Informix OleDb Provider
  
  
  1. using System.Data.OleDb;
  2.  
  3. var conn = new OleDbConnection();
  4. conn.ConnectionString =
  5. "Driver=IFXOLEDBC;" +
  6. "Data Source=DataBaseName@ServerName;" +
  7. "User id=UserName;" +
  8. "Password=Secret;";
  9. "Persist Security Info=true;";
  10. conn.Open();





Excel



ODBC DSN
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Dsn=DsnName;" +
  6. "Uid=UserName;" +
  7. "Pwd=Secret;";
  8. conn.Open();


ODBC without DSN
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Driver={Microsoft Excel Driver (*.xls)};" +
  6. "Driverid=790;" +
  7. "Dbq=C:\MyPath\SpreadSheet.xls;" +
  8. "DefaultDir=C:\MyPath;";
  9. conn.Open();


OleDb with MS Jet
  
  
  1. using System.Data.OleDb;
  2.  
  3. var conn = new OleDbConnection();
  4. conn.ConnectionString =
  5. "Driver=Microsoft.Jet.OLEDB.4.0;" +
  6. "Data Source=C:\MyPath\SpreadSheet.xls;" +
  7. @"Extended Properties=""Excel 8.0;HDR=Yes""";
  8. conn.Open();
<





Text



ODBC DSN
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Dsn=DsnName;" +
  6. "Uid=UserName;" +
  7. "Pwd=Secret;";
  8. conn.Open();


ODBC without DSN
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Driver={Microsoft Text Driver (*.txt; *.csv)};" +
  6. "Dbq=C:\MyPath\;" +
  7. "Extensions=asc,csv,tab,txt;";
  8. conn.Open();
  9.  
  10. // Use: sql = "Select * From MyTextFile.txt"


OleDb with MS Jet
  
  
  1. using System.Data.OleDb;
  2.  
  3. var conn = new OleDbConnection();
  4. conn.ConnectionString =
  5. "Driver=Microsoft.Jet.OLEDB.4.0;" +
  6. "Data Source=C:\MyPath\;" +
  7. "Extended Properties=" +
  8. @"""text;HDR=Yes;FMT=Delimited""";
  9. conn.Open();
  10.  
  11. // Use: sql = "Select * From MyTextFile.txt"





dBase Dbf



ODBC DSN
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString = "Dsn=DsnName";
  5. conn.Open();
  6.  
  7. // Use: sql = "Select * From MyDb.dbf"


ODBC without DSN
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Driver={Microsoft dBASE Driver (*.dbf)};" +
  6. "Driverid=277;" +
  7. "Dbq=C:\MyPath\";
  8. conn.Open();
  9.  
  10. // Use: sql = "Select * From MyDb.dbf"





Visual FoxPro



ODBC DSN
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString = "Dsn=DsnName";
  5. conn.Open();


ODBC without DSN -- Database container (dbc)
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Driver={Microsoft Visual FoxPro Driver};" +
  6. "SourceType=DBC;" +
  7. "SourceDB=C:\MyPath\MyDb.dbc;" +
  8. "Exclusive=No";
  9. conn.Open();


ODBC without DSN -- Free table directory
  
  
  1. using System.Data.Odbc;
  2.  
  3. var conn = new OdbcConnection();
  4. conn.ConnectionString =
  5. "Driver={Microsoft Visual FoxPro Driver};" +
  6. "SourceType=DBF;" +
  7. "SourceDB=C:\MyPath;" +
  8. "Exclusive=No";
  9. conn.Open();


OleDb -- Database container (dbc)
  
  
  1. using System.Data.OleDb;
  2.  
  3. var conn = new OleDbConnection();
  4. conn.ConnectionString =
  5. "Driver=VFPOLEDB;" +
  6. "Data Source=C:\MyPath\MyDb.dbc;" +
  7. "Collating Sequence=machine;" +
  8. "Password=Secret;";
  9. conn.Open();


OleDb -- Free table directory
  
  
  1. using System.Data.OleDb;
  2.  
  3. var conn = new OleDbConnection();
  4. conn.ConnectionString =
  5. "Driver=VFPOLEDB;" +
  6. "Data Source=C:\MyPath\;" +
  7. "Collating Sequence=general;" +
  8. "Password=Secret;";
  9. conn.Open();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值