DOT NET Examples - Connect to a database as current user
From Ingres Community Wiki
[edit]
Example .NET Data Provider Application
This simple example shows how to connect to Ingres using the Ingres .NET Data Provider. The connection string defaults to Port=II7 and to the current user credentials.
[edit]
The Example of .NET Source Code
You can cut and paste this into your favorite editor:
using Ingres.Client;
void SampleCode()
{
string myConnectionString =
"Host=myserver; database=mydatabase";
IngresConnection conn = new IngresConnection(myConnectionString);
conn.Open();
// <do work>
conn.Close();
}
[edit]
A Better Example of .NET Source Code
This example uses a better programming practice of specifying a "using" scope to ensure that the IngresConnection is closed should an exception occur while doing database work. The "using" scope behaves like a try/finally block.
using Ingres.Client;
void SampleCode2()
{
string myConnectionString =
"Host=myserver;database=mydatabase";
using (IngresConnection conn = new IngresConnection(myConnectionString))
{
conn.Open();
// <do work>
} // end using IngresConnection
}
Back to DOT NET Examples
Categories: Examples | Articles | DOTNET | DBMSDrivers
