What is the connection string for odbc connections?

I always made web applications, and now I need to make a console application. I need to use both odbc connection and regular connection.

In the past, I would use:

<add name="LinkConnectionString" connectionString="Data Source=SERENITY\SQLEXPRESS;Initial Catalog=Link;Integrated Security=True" providerName="System.Data.SqlClient"/>

In web.config, however, I'm not sure how to do the same with inline code. Since the string connectionString = @ ".....";

I tried several combinations, looked online (including connectionstrings.com), but none of them worked.

Can anyone help me out? I want both odbc and regular ... since they seem different, they should be different according to the online patterns (which doesn't work).

+3
source share
5 answers

- , " " - .txt. .udl, - . ok, , , .

28 2009 . (powershell script):

function get-oledbconnection ([switch]$Open) {
    $null | set-content ($udl = "$([io.path]::GetTempPath())\temp.udl");
    $psi = new-object Diagnostics.ProcessStartInfo
    $psi.CreateNoWindow = $true
    $psi.UseShellExecute = $true
    $psi.FileName = $udl
    $pi = [System.Diagnostics.Process]::Start($psi)
    $pi.WaitForExit()
    write-host (gc $udl) # verbose 
    if (gc $udl) {
        $conn = new-object data.oledb.oledbconnection (gc $udl)[2]
        if ($Open) { $conn.Open() }
    }
    $conn
}
+42

, :

http://www.connectionstrings.com/

:

"DRIVER = {}; SERVER = server.database; UID = ; PWD = "

+9

Have you tried something like this for SQLServer?

  SqlConnection conn = new SqlConnection(@"Data Source=SERENITY\SQLEXPRESS;Initial Catalog=Link;Integrated Security=True");
  SqlCommand cmd = new SqlCommand("SELECT * FROM tableName", conn);
  conn.Open();
  //<snip> Run Command
  conn.Close();

and for ODBC

OdbcConnection conn = new OdbcConnection(@"ODBC connection string");
OdbcCommand cmd = new OdbcCommand("SELECT * FROM tableName", conn);
conn.Open();
//Run Command
conn.Close();
0
source

<add name="myName" connectionString="dsn=myDSN;UID=myUID;" providerName="System.Data.Odbc" />

0
source

Source: https://habr.com/ru/post/1699234/


All Articles