Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the connection string for odbc connections?

I've always done web apps and now I need to do a console app. I need to use both an odbc connection and a regular connection.

In the past I would have used:

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

In the web.config, however I am not sure how to do the same thing with inline code. So like string connectionString = @".....";

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

Can anyone help me out? I want both the odbc and the regular... as they seem different should be different according to the sample ones online (that don't work).

like image 259
rksprst Avatar asked Nov 26 '22 21:11

rksprst


2 Answers

A cool trick to building connection strings is to right click on your desktop, choose "new text document" - this will make a temporary notepad .txt file. Rename it to .udl and then double click it - you can now create any connection string. Click ok when done and open the file in notepad to see the connectionstring.

UPDATED April 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
}
like image 60
x0n Avatar answered Dec 04 '22 08:12

x0n


You should be able to find whatever you need here:

http://www.connectionstrings.com/

For one of our apps we use this connection string:

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

like image 22
jonnii Avatar answered Dec 04 '22 10:12

jonnii