Re: Creating connection string (i think)
- From: "Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin@xxxxxxxxx>
- Date: Fri, 1 Aug 2008 11:08:54 -0700 (PDT)
On Aug 1, 11:46 am, "Ignacio Machin ( .NET/ C# MVP )"
<ignacio.mac...@xxxxxxxxx> wrote:
On Aug 1, 10:50 am, "K Viltersten" <t...@xxxxxxxxxxxxxx> wrote:
I'm getting "connection not initialized" for
error when running the following code.
You are missing a single line :)
cmn.Connection = con;
BTW, you should code your code in this way:
using (SqlConnection con = new SqlConnection(conStr) )
{
con.Open();
using (SqlCommand cmd = new SqlCommand("select * from
the_table", con) )
{
cmd.ExecuteNonQuery()
}
}
in this way you make sure that the objects are disposed correctly,
even in the presence of an exception.
.
- Follow-Ups:
- Re: Creating connection string (i think)
- From: K Viltersten
- Re: Creating connection string (i think)
- References:
- Creating connection string (i think)
- From: K Viltersten
- Re: Creating connection string (i think)
- From: Ignacio Machin ( .NET/ C# MVP )
- Creating connection string (i think)
- Prev by Date: Re: Background Thread Issue
- Next by Date: Re: Extention method return types
- Previous by thread: Re: Creating connection string (i think)
- Next by thread: Re: Creating connection string (i think)
- Index(es):
Relevant Pages
|