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).
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
}
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With