Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you're using ASP.Net, option A is your friend.</p> <p>Create a new connection for each request, Dispose()-ing when the request is complete. Ensure that you use <strong>identical</strong> connect strings. The connections will (by default) remain open and available through a connection pool.</p> <p>See <a href="http://msdn.microsoft.com/en-us/library/8xx3tyca.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/8xx3tyca.aspx</a> for more information on connection pooling.</p> <p>You pretty much have to do it this way in a web server so you don't have concurrency issues anyway. Everything needs to be thread-safe (you've got no idea how many concurrent worker threads are executing in your app).</p> <p>[edited to add example code]</p> <p>As an example, here's what I would consider to be a typical method to execute a stored procedure. This comes from a custom code generator I wrote &mdash; handwritten code will likely look a little different &mdash; but it should suffice to get the point across:</p> <pre><code>public int Exec( int? @iPatientID ) { using ( SqlConnection conn = new SqlConnection( this.ConnectString ) ) using ( SqlCommand cmd = conn.CreateCommand() ) using ( SqlDataAdapter sda = new SqlDataAdapter( cmd ) ) { cmd.CommandText = STORED_PROCEDURE_NAME ; cmd.CommandType = CommandType.StoredProcedure ; if ( this.TimeoutInSeconds.HasValue ) { cmd.CommandTimeout = this.TimeoutInSeconds.Value ; } // // 1. @iPatientID // SqlParameter p1 = new SqlParameter( @"@iPatientID" , SqlDbType.Int ) ; if ( @iPatientID == null ) { p1.Value = System.DBNull.Value ; } else { p1.Value = @iPatientID ; } cmd.Parameters.Add( p1 ) ; // add return code parameter SqlParameter pReturnCode = new SqlParameter() ; pReturnCode.SqlDbType = System.Data.SqlDbType.Int ; pReturnCode.Direction = System.Data.ParameterDirection.ReturnValue ; cmd.Parameters.Add( pReturnCode ) ; DataSet ds = new DataSet() ; conn.Open() ; sda.Fill( ds ) ; conn.Close() ; this.ResultSet = ( ds.Tables.Count &gt; 0 ? ds.Tables[0] : null ) ; this.ReturnCode = (int) pReturnCode.Value ; } return this.ReturnCode ; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload