In this article, I have listed C# code snippets of connection string for Text Database.
Text Database Connection String in C#:
Connection String provide the required information to the driver that tells where to find the default connection information. Optionally, you are allowed to specify attribute=value pairs in the connection string to override the default values stored in the data source.
1. ODBC DSN
1 2 3 4 5 6 7 |
using System.Data.Odbc; var conn = new OdbcConnection(); conn.ConnectionString = "Dsn=DsnName;" + "Uid=UserName;" + "Pwd=Secret;"; conn.Open(); |
2. ODBC without DSN
1 2 3 4 5 6 7 8 9 |
using System.Data.Odbc; var conn = new OdbcConnection(); conn.ConnectionString = "Driver={Microsoft Text Driver (*.txt; *.csv)};" + "Dbq=C:\MyPath\;" + "Extensions=asc,csv,tab,txt;"; conn.Open(); //Use select query -> sql = "Select * From AnyTextFile.txt" |
3. OleDb with MS Jet
1 2 3 4 5 6 7 8 9 10 |
using System.Data.OleDb; var conn = new OleDbConnection(); conn.ConnectionString = "Driver=Microsoft.Jet.OLEDB.4.0;" + "Data Source=C:\MyPath\;" + "Extended Properties=" + @"""text;HDR=Yes;FMT=Delimited"""; conn.Open(); //Use select query -> sql = "Select * From AnyTextFile.txt" |
– Article ends here –