ADO.NET - SqlHelper question

Results 1 to 2 of 2

Thread: ADO.NET - SqlHelper question

  1. #1
    Join Date
    Dec 1969

    Default ADO.NET - SqlHelper question

    Does anyone know how the SqlHelper functionality in the Microsoft Data Access Application Block works? I need to know what happens in the SqlHelper.FillDataset() method when you pass in a connection string as the first parameter. <BR><BR>Does FillDataset create a connection to the database and close it before returning to the calling function, or does it stay open and wait for the garbage collector? <BR><BR>FillDataset is overloaded, and currently we&#039;re using it with #2, which accepts a connection string, command type, command text, dataset, table name(s), and parameters) this:<BR><BR> sqlParameters(0) = CreateSqlIntParameter("@RowId", 10, RowId)<BR> sqlParameters(1) = CreateSqlVarcharParameter("@RowType", 8, RowType)<BR> <BR> &#039; Populate the dataset with reader rows<BR><BR> SqlHelper.FillDataset(ConnectionString, _<BR> CommandType.StoredProcedure, _<BR> "my_StoredProcedure", _<BR> myDataset, _<BR> New String() {"myTable"}, _<BR> sqlParameters) <BR><BR>One of the other possibilities is to open a SqlConnection, and pass the connection into the first parameter rather than the string. The I would be responsible for closing the connection manually.<BR><BR>I&#039;m getting connection pooling errors when testing locally, so I want someone who knows to tell me whether there&#039;s an advantage to creating my own connection, or letting SqlHelper.FillDataset do it for me. In order to test different scenarios, I have to change a LOT of code...I&#039;m hoping newsgroup advice is quicker.<BR><BR>Thanks!

  2. #2
    Join Date
    Dec 1969

    Default One of the cool things...

    About the DAAB, is that it ships with the soruce code, so you can get in and see exactly what it&#039;s doing. <BR><BR>So, a quick look tells me that it *is* calling .Dispose() on the connection when it returns (via a using block).<BR><BR>The relevant method:<BR>[code language="C#"]<BR> public static void FillDataset(string connectionString, string spName,<BR> DataSet dataSet, string[] tableNames,<BR> params object[] parameterValues)<BR> {<BR> if( connectionString == null &#124&#124 connectionString.Length == 0 ) throw new ArgumentNullException( "connectionString" );<BR> if( dataSet == null ) throw new ArgumentNullException( "dataSet" );<BR> // Create & open a SqlConnection, and dispose of it after we are done<BR> using (SqlConnection connection = new SqlConnection(connectionString))<BR> {<BR> connection.Open();<BR><BR> // Call the overload that takes a connection in place of the connection string<BR> FillDataset (connection, spName, dataSet, tableNames, parameterValues);<BR> }<BR> }<BR>[/code]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts