SqlDataAdapter.Fill exception in Release but not Debug Mode

G

Guest

I apologize in advance for the lengthy post, but any help or insight would be
greatly appreciated!

I've been having a problem with the SqlDataAdapter's Fill method while
attempting to fill a dataset with the results of a query I execute against a
SQL Server 2005 database. The exception only occurs in release mode, not in
debug mode. Additionally, the exception seems to be occuring when I query a
particular table (I am able to query other tables which have fewer fields \
records without difficulty).

The query I am using is: SELECT * FROM tablename

I've included a sample of the code I am using below. This function is part
of a class I created to handle querying my database.

Other information which may be of use: I am using VB.NET 2005, connecting to
SQL Server 2005 (db is on the same machine as the exe I am creating). I know
my connectionstring is valid as I have a series of validation functions which
execute when the user logs into my application to verify that they have
permission to the database and are part of certain roles within SQL Server
prior to allowing them access to the application.

I have gotten so frustrated with this exception that I have changed my code
to use OleDB instead of the SqlClient and the query throwing the exception
works when I use OleDB!

Has anyone out there experienced anything similar? If so, were you able to
determine what was causing the error? At this point I have code which works
but I would love to know why I get the error using SqlClient and only in
Release Mode.

Sample Function:

Private m_ConnString As String
Private m_CN As SqlClient.SqlConnection

Public Function GetDataSet(ByVal SQL As String) As DataSet

Dim ds As DataSet

Try

m_CN = New SqlClient.SqlConnection(m_ConnString)
m_CN.Open()

Dim cmd As New SqlClient.SqlCommand(SQL, m_CN)
Dim Adapt As New SqlClient.SqlDataAdapter(cmd)

ds = New DataSet()

Adapt.Fill(ds) 'Error Seems to be occuring here

Catch Ex As Exception
Throw
End Try

Return ds

End Function

StackTrace output when exception occurs:

DefaultSource Error: 2 : Object reference not set to an instance of an
object. at System.Data.SqlClient.SqlDataReader.ReadColumnData()
at System.Data.SqlClient.SqlDataReader.ReadColumn(Int32 i, Boolean
setTimeout)
at System.Data.SqlClient.SqlDataReader.GetValueInternal(Int32 i)
at System.Data.SqlClient.SqlDataReader.GetValues(Object[] values)
at
System.Data.ProviderBase.DataReaderContainer.CommonLanguageSubsetDataReader.GetValues(Object[] values)
at System.Data.ProviderBase.SchemaMapping.LoadDataRow()
at System.Data.Common.DataAdapter.FillLoadDataRow(SchemaMapping mapping)
at System.Data.Common.DataAdapter.FillFromReader(DataSet dataset,
DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32
startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object
parentChapterValue)
at System.Data.Common.DataAdapter.Fill(DataSet dataSet, String srcTable,
IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset,
DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable,
IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32
startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
at SqlManager.CAPSDB.GetDataSet(String Sql, Int32 Timeout) in
C:\Projects\VisualStudioNET\SQLManager\SQLManager\CAPSDB.vb:line 124
at SqlManager.frmMgr.ExecuteQuery(Boolean ShiftKeyPressed) in
C:\Projects\VisualStudioNET\SQLManager\SQLManager\frmMgr.vb:line 176
 
C

Cor Ligthert [MVP]

TLentine,

I don't have the answer but I know that your question is not new, can you
have a look yourself what is written about that in this newsgroup.

http://groups.google.com/group/micr...lease+mode&qt_g=1&searchnow=Search+this+group

I hope this helps,

Cor

TLentine said:
I apologize in advance for the lengthy post, but any help or insight would
be
greatly appreciated!

I've been having a problem with the SqlDataAdapter's Fill method while
attempting to fill a dataset with the results of a query I execute against
a
SQL Server 2005 database. The exception only occurs in release mode, not
in
debug mode. Additionally, the exception seems to be occuring when I query
a
particular table (I am able to query other tables which have fewer fields
\
records without difficulty).

The query I am using is: SELECT * FROM tablename

I've included a sample of the code I am using below. This function is part
of a class I created to handle querying my database.

Other information which may be of use: I am using VB.NET 2005, connecting
to
SQL Server 2005 (db is on the same machine as the exe I am creating). I
know
my connectionstring is valid as I have a series of validation functions
which
execute when the user logs into my application to verify that they have
permission to the database and are part of certain roles within SQL Server
prior to allowing them access to the application.

I have gotten so frustrated with this exception that I have changed my
code
to use OleDB instead of the SqlClient and the query throwing the exception
works when I use OleDB!

Has anyone out there experienced anything similar? If so, were you able to
determine what was causing the error? At this point I have code which
works
but I would love to know why I get the error using SqlClient and only in
Release Mode.

Sample Function:

Private m_ConnString As String
Private m_CN As SqlClient.SqlConnection

Public Function GetDataSet(ByVal SQL As String) As DataSet

Dim ds As DataSet

Try

m_CN = New SqlClient.SqlConnection(m_ConnString)
m_CN.Open()

Dim cmd As New SqlClient.SqlCommand(SQL, m_CN)
Dim Adapt As New SqlClient.SqlDataAdapter(cmd)

ds = New DataSet()

Adapt.Fill(ds) 'Error Seems to be occuring here

Catch Ex As Exception
Throw
End Try

Return ds

End Function

StackTrace output when exception occurs:

DefaultSource Error: 2 : Object reference not set to an instance of an
object. at System.Data.SqlClient.SqlDataReader.ReadColumnData()
at System.Data.SqlClient.SqlDataReader.ReadColumn(Int32 i, Boolean
setTimeout)
at System.Data.SqlClient.SqlDataReader.GetValueInternal(Int32 i)
at System.Data.SqlClient.SqlDataReader.GetValues(Object[] values)
at
System.Data.ProviderBase.DataReaderContainer.CommonLanguageSubsetDataReader.GetValues(Object[]
values)
at System.Data.ProviderBase.SchemaMapping.LoadDataRow()
at System.Data.Common.DataAdapter.FillLoadDataRow(SchemaMapping mapping)
at System.Data.Common.DataAdapter.FillFromReader(DataSet dataset,
DataTable datatable, String srcTable, DataReaderContainer dataReader,
Int32
startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object
parentChapterValue)
at System.Data.Common.DataAdapter.Fill(DataSet dataSet, String srcTable,
IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset,
DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String
srcTable,
IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32
startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
at SqlManager.CAPSDB.GetDataSet(String Sql, Int32 Timeout) in
C:\Projects\VisualStudioNET\SQLManager\SQLManager\CAPSDB.vb:line 124
at SqlManager.frmMgr.ExecuteQuery(Boolean ShiftKeyPressed) in
C:\Projects\VisualStudioNET\SQLManager\SQLManager\frmMgr.vb:line 176
 
E

Earl

The only time I had a similar problem was using typed datasets and the
connection string was different in the connection object than what I was
using for a particular fill.

TLentine said:
I apologize in advance for the lengthy post, but any help or insight would
be
greatly appreciated!

I've been having a problem with the SqlDataAdapter's Fill method while
attempting to fill a dataset with the results of a query I execute against
a
SQL Server 2005 database. The exception only occurs in release mode, not
in
debug mode. Additionally, the exception seems to be occuring when I query
a
particular table (I am able to query other tables which have fewer fields
\
records without difficulty).

The query I am using is: SELECT * FROM tablename

I've included a sample of the code I am using below. This function is part
of a class I created to handle querying my database.

Other information which may be of use: I am using VB.NET 2005, connecting
to
SQL Server 2005 (db is on the same machine as the exe I am creating). I
know
my connectionstring is valid as I have a series of validation functions
which
execute when the user logs into my application to verify that they have
permission to the database and are part of certain roles within SQL Server
prior to allowing them access to the application.

I have gotten so frustrated with this exception that I have changed my
code
to use OleDB instead of the SqlClient and the query throwing the exception
works when I use OleDB!

Has anyone out there experienced anything similar? If so, were you able to
determine what was causing the error? At this point I have code which
works
but I would love to know why I get the error using SqlClient and only in
Release Mode.

Sample Function:

Private m_ConnString As String
Private m_CN As SqlClient.SqlConnection

Public Function GetDataSet(ByVal SQL As String) As DataSet

Dim ds As DataSet

Try

m_CN = New SqlClient.SqlConnection(m_ConnString)
m_CN.Open()

Dim cmd As New SqlClient.SqlCommand(SQL, m_CN)
Dim Adapt As New SqlClient.SqlDataAdapter(cmd)

ds = New DataSet()

Adapt.Fill(ds) 'Error Seems to be occuring here

Catch Ex As Exception
Throw
End Try

Return ds

End Function

StackTrace output when exception occurs:

DefaultSource Error: 2 : Object reference not set to an instance of an
object. at System.Data.SqlClient.SqlDataReader.ReadColumnData()
at System.Data.SqlClient.SqlDataReader.ReadColumn(Int32 i, Boolean
setTimeout)
at System.Data.SqlClient.SqlDataReader.GetValueInternal(Int32 i)
at System.Data.SqlClient.SqlDataReader.GetValues(Object[] values)
at
System.Data.ProviderBase.DataReaderContainer.CommonLanguageSubsetDataReader.GetValues(Object[]
values)
at System.Data.ProviderBase.SchemaMapping.LoadDataRow()
at System.Data.Common.DataAdapter.FillLoadDataRow(SchemaMapping mapping)
at System.Data.Common.DataAdapter.FillFromReader(DataSet dataset,
DataTable datatable, String srcTable, DataReaderContainer dataReader,
Int32
startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object
parentChapterValue)
at System.Data.Common.DataAdapter.Fill(DataSet dataSet, String srcTable,
IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset,
DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String
srcTable,
IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32
startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
at SqlManager.CAPSDB.GetDataSet(String Sql, Int32 Timeout) in
C:\Projects\VisualStudioNET\SQLManager\SQLManager\CAPSDB.vb:line 124
at SqlManager.frmMgr.ExecuteQuery(Boolean ShiftKeyPressed) in
C:\Projects\VisualStudioNET\SQLManager\SQLManager\frmMgr.vb:line 176
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top