VS2005 and SQL Express: Internal .Net Framework Data Provider erro

G

Guest

Hi everybody,

Is there anybody can tell me what this error meant? Where is source of
error? There is a class library DLL created by another person. I used C# (VS
2005 Professional Edition) and SQL Server 2005 Express Edition and also used
Visual SourceSafe 6.0.

In this class,
There is a constructor and destructor in the destructor it calls the
CloseConnection() method where the error occurs.

Code:
I am using this methods


public void CreateConnection(string ConnectionString) {
// Check first if the connection is open, if yes, close it first
before creating a new one
CloseConnection();
// Create the SQLConnection object for the class to use
m_Connection = new SqlConnection(ConnectionString);
}
public void CreateCommand(string StoredProcName) {
// Check first if the command is existing, if yes, set it first
to null before creating a new one
CloseCommand();
// Check if there is an SQLConnection object existing for the
command to use
if (m_Connection == null)
CreateConnection();
// Create the SQLCommand object for the class to use
m_Command = new SqlCommand();
m_Command.Connection = m_Connection;
m_Command.CommandType = CommandType.StoredProcedure;
m_Command.CommandText = StoredProcName;
}

public void AddParameter(string ParamName, object ParamValue) {
// Check if there is an SQLCommand existing before adding the
parameters. If not, then return an exception.
if (m_Command == null)
throw new NullReferenceException("Command Object is null.
Please execute CreateCommand first before adding parameters.");

// Add the parameter to the SQLCommand object
SqlParameter parameter;
parameter = m_Command.CreateParameter();
parameter.ParameterName = ParamName;
parameter.Value = ParamValue;
m_Command.Parameters.Add(parameter);
parameter = null;
}

public void ExecuteReader() {
// Check if there is an SQLCommand existing before executing
Data Reader. If not, then return an exception.
if (m_Command == null)
throw new NullReferenceException("Command Object is null.");
// Check if the connection state of the SQLConnection object is
open, if not open it.
if (m_Connection.State == ConnectionState.Closed)
m_Connection.Open();
// Close first and dispose the existing data reader is there is
any
CloseDataReader();
// Create the data reader
m_DataReader = m_Command.ExecuteReader();
}


Code:
~DataAccessLayer() {
Dispose(true);
}


private void CloseConnection()
{
if (m_Connection != null) {
try {
// Check if connection is already closed, if not, then
close it
if (m_Connection.State != ConnectionState.Closed)
m_Connection.Close(); <<---Error Occurs here
// Dispose the connection object and set it to null to
release resources used by the object
m_Connection.Dispose();
m_Connection = null;
}
catch {
throw;
}
}
}

private void CloseCommand() {
if (m_Command != null) {
try {
// Dispose the command object and set it to null to
release resources used by the object
m_Command.Dispose();
m_Command = null;
}
catch {
throw;
}
}
}
private void CloseDataReader() {
if (m_DataReader != null) {
try {
// Check if datareader is already closed, if not, then
close it
if (!m_DataReader.IsClosed)
m_DataReader.Close();
// Set datareader to null
m_DataReader = null;
}
catch {
throw;
}
}
}
private void CloseDataSet() {
if (m_DataSet != null) {
try {
// Dispose object to release resources used
m_DataSet.Dispose();
m_DataSet = null;
}
catch {
throw;
}
}
}

public void Dispose() {
this.Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing) {
// Check to see if Dispose has already been called.
if (!this.m_Disposed) {
if (disposing) {
// Dispose managed resources.
CloseDataReader();
CloseDataSet();
CloseCommand();
CloseConnection();
}
// Release unmanaged resources. If disposing is false,
// only the following code is executed.
}
m_Disposed = true;
}

So Base on this codes, what is the problem?

Thanks in Advanced.


den2005
 
C

Cowboy \(Gregory A. Beamer\)

What is the error precisely? THe interal connection is underneath the
connection object you use. This allows for connection pooling, etc. The
closing of the connection prior to creating a new one is one shot, but I do
not see what is calling this.

Run through debug until it dies and focus on the exact location. Then, back
up a few lines, put a breakpoint and walk through. You will eventually find
the precise error location. If my thinking is correct, you are ending up
with the inability to re-instantiate the object as it is in the midst of
destruction, but this is just a guess.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside of the box!
*************************************************
den 2005 said:
Hi everybody,

Is there anybody can tell me what this error meant? Where is source of
error? There is a class library DLL created by another person. I used C#
(VS
2005 Professional Edition) and SQL Server 2005 Express Edition and also
used
Visual SourceSafe 6.0.

In this class,
There is a constructor and destructor in the destructor it calls the
CloseConnection() method where the error occurs.

Code:
I am using this methods


public void CreateConnection(string ConnectionString) {
// Check first if the connection is open, if yes, close it
first
before creating a new one
CloseConnection();
// Create the SQLConnection object for the class to use
m_Connection = new SqlConnection(ConnectionString);
}
public void CreateCommand(string StoredProcName) {
// Check first if the command is existing, if yes, set it first
to null before creating a new one
CloseCommand();
// Check if there is an SQLConnection object existing for the
command to use
if (m_Connection == null)
CreateConnection();
// Create the SQLCommand object for the class to use
m_Command = new SqlCommand();
m_Command.Connection = m_Connection;
m_Command.CommandType = CommandType.StoredProcedure;
m_Command.CommandText = StoredProcName;
}

public void AddParameter(string ParamName, object ParamValue) {
// Check if there is an SQLCommand existing before adding the
parameters. If not, then return an exception.
if (m_Command == null)
throw new NullReferenceException("Command Object is null.
Please execute CreateCommand first before adding parameters.");

// Add the parameter to the SQLCommand object
SqlParameter parameter;
parameter = m_Command.CreateParameter();
parameter.ParameterName = ParamName;
parameter.Value = ParamValue;
m_Command.Parameters.Add(parameter);
parameter = null;
}

public void ExecuteReader() {
// Check if there is an SQLCommand existing before executing
Data Reader. If not, then return an exception.
if (m_Command == null)
throw new NullReferenceException("Command Object is
null.");
// Check if the connection state of the SQLConnection object is
open, if not open it.
if (m_Connection.State == ConnectionState.Closed)
m_Connection.Open();
// Close first and dispose the existing data reader is there is
any
CloseDataReader();
// Create the data reader
m_DataReader = m_Command.ExecuteReader();
}


Code:
~DataAccessLayer() {
Dispose(true);
}


private void CloseConnection()
{
if (m_Connection != null) {
try {
// Check if connection is already closed, if not, then
close it
if (m_Connection.State != ConnectionState.Closed)
m_Connection.Close(); <<---Error Occurs here
// Dispose the connection object and set it to null to
release resources used by the object
m_Connection.Dispose();
m_Connection = null;
}
catch {
throw;
}
}
}

private void CloseCommand() {
if (m_Command != null) {
try {
// Dispose the command object and set it to null to
release resources used by the object
m_Command.Dispose();
m_Command = null;
}
catch {
throw;
}
}
}
private void CloseDataReader() {
if (m_DataReader != null) {
try {
// Check if datareader is already closed, if not, then
close it
if (!m_DataReader.IsClosed)
m_DataReader.Close();
// Set datareader to null
m_DataReader = null;
}
catch {
throw;
}
}
}
private void CloseDataSet() {
if (m_DataSet != null) {
try {
// Dispose object to release resources used
m_DataSet.Dispose();
m_DataSet = null;
}
catch {
throw;
}
}
}

public void Dispose() {
this.Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing) {
// Check to see if Dispose has already been called.
if (!this.m_Disposed) {
if (disposing) {
// Dispose managed resources.
CloseDataReader();
CloseDataSet();
CloseCommand();
CloseConnection();
}
// Release unmanaged resources. If disposing is false,
// only the following code is executed.
}
m_Disposed = true;
}

So Base on this codes, what is the problem?

Thanks in Advanced.


den2005
 
G

Guest

Thanks Gregory for the reply..

The error occurs when the connection is being close, I think triggered in
the destructor...It works in 1.1 and Sql 2000 as my co-workers using this
class. Wel, I created a new class without the destructor..

dennis
--
MCP Year 2005, Philippines


Cowboy (Gregory A. Beamer) said:
What is the error precisely? THe interal connection is underneath the
connection object you use. This allows for connection pooling, etc. The
closing of the connection prior to creating a new one is one shot, but I do
not see what is calling this.

Run through debug until it dies and focus on the exact location. Then, back
up a few lines, put a breakpoint and walk through. You will eventually find
the precise error location. If my thinking is correct, you are ending up
with the inability to re-instantiate the object as it is in the midst of
destruction, but this is just a guess.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside of the box!
*************************************************
den 2005 said:
Hi everybody,

Is there anybody can tell me what this error meant? Where is source of
error? There is a class library DLL created by another person. I used C#
(VS
2005 Professional Edition) and SQL Server 2005 Express Edition and also
used
Visual SourceSafe 6.0.

In this class,
There is a constructor and destructor in the destructor it calls the
CloseConnection() method where the error occurs.

Code:
I am using this methods


public void CreateConnection(string ConnectionString) {
// Check first if the connection is open, if yes, close it
first
before creating a new one
CloseConnection();
// Create the SQLConnection object for the class to use
m_Connection = new SqlConnection(ConnectionString);
}
public void CreateCommand(string StoredProcName) {
// Check first if the command is existing, if yes, set it first
to null before creating a new one
CloseCommand();
// Check if there is an SQLConnection object existing for the
command to use
if (m_Connection == null)
CreateConnection();
// Create the SQLCommand object for the class to use
m_Command = new SqlCommand();
m_Command.Connection = m_Connection;
m_Command.CommandType = CommandType.StoredProcedure;
m_Command.CommandText = StoredProcName;
}

public void AddParameter(string ParamName, object ParamValue) {
// Check if there is an SQLCommand existing before adding the
parameters. If not, then return an exception.
if (m_Command == null)
throw new NullReferenceException("Command Object is null.
Please execute CreateCommand first before adding parameters.");

// Add the parameter to the SQLCommand object
SqlParameter parameter;
parameter = m_Command.CreateParameter();
parameter.ParameterName = ParamName;
parameter.Value = ParamValue;
m_Command.Parameters.Add(parameter);
parameter = null;
}

public void ExecuteReader() {
// Check if there is an SQLCommand existing before executing
Data Reader. If not, then return an exception.
if (m_Command == null)
throw new NullReferenceException("Command Object is
null.");
// Check if the connection state of the SQLConnection object is
open, if not open it.
if (m_Connection.State == ConnectionState.Closed)
m_Connection.Open();
// Close first and dispose the existing data reader is there is
any
CloseDataReader();
// Create the data reader
m_DataReader = m_Command.ExecuteReader();
}


Code:
~DataAccessLayer() {
Dispose(true);
}


private void CloseConnection()
{
if (m_Connection != null) {
try {
// Check if connection is already closed, if not, then
close it
if (m_Connection.State != ConnectionState.Closed)
m_Connection.Close(); <<---Error Occurs here
// Dispose the connection object and set it to null to
release resources used by the object
m_Connection.Dispose();
m_Connection = null;
}
catch {
throw;
}
}
}

private void CloseCommand() {
if (m_Command != null) {
try {
// Dispose the command object and set it to null to
release resources used by the object
m_Command.Dispose();
m_Command = null;
}
catch {
throw;
}
}
}
private void CloseDataReader() {
if (m_DataReader != null) {
try {
// Check if datareader is already closed, if not, then
close it
if (!m_DataReader.IsClosed)
m_DataReader.Close();
// Set datareader to null
m_DataReader = null;
}
catch {
throw;
}
}
}
private void CloseDataSet() {
if (m_DataSet != null) {
try {
// Dispose object to release resources used
m_DataSet.Dispose();
m_DataSet = null;
}
catch {
throw;
}
}
}

public void Dispose() {
this.Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing) {
// Check to see if Dispose has already been called.
if (!this.m_Disposed) {
if (disposing) {
// Dispose managed resources.
CloseDataReader();
CloseDataSet();
CloseCommand();
CloseConnection();
}
// Release unmanaged resources. If disposing is false,
// only the following code is executed.
}
m_Disposed = true;
}

So Base on this codes, what is the problem?

Thanks in Advanced.


den2005
 
C

Cowboy \(Gregory A. Beamer\)

I am familiar with that one, as I did the same awhile back. I was trying to
remember the specifics. I am glad you found your answer.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside of the box!
*************************************************
den 2005 said:
Thanks Gregory for the reply..

The error occurs when the connection is being close, I think triggered in
the destructor...It works in 1.1 and Sql 2000 as my co-workers using this
class. Wel, I created a new class without the destructor..

dennis
--
MCP Year 2005, Philippines


Cowboy (Gregory A. Beamer) said:
What is the error precisely? THe interal connection is underneath the
connection object you use. This allows for connection pooling, etc. The
closing of the connection prior to creating a new one is one shot, but I
do
not see what is calling this.

Run through debug until it dies and focus on the exact location. Then,
back
up a few lines, put a breakpoint and walk through. You will eventually
find
the precise error location. If my thinking is correct, you are ending up
with the inability to re-instantiate the object as it is in the midst of
destruction, but this is just a guess.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside of the box!
*************************************************
den 2005 said:
Hi everybody,

Is there anybody can tell me what this error meant? Where is source of
error? There is a class library DLL created by another person. I used
C#
(VS
2005 Professional Edition) and SQL Server 2005 Express Edition and also
used
Visual SourceSafe 6.0.

In this class,
There is a constructor and destructor in the destructor it calls the
CloseConnection() method where the error occurs.

Code:
I am using this methods


public void CreateConnection(string ConnectionString) {
// Check first if the connection is open, if yes, close it
first
before creating a new one
CloseConnection();
// Create the SQLConnection object for the class to use
m_Connection = new SqlConnection(ConnectionString);
}
public void CreateCommand(string StoredProcName) {
// Check first if the command is existing, if yes, set it
first
to null before creating a new one
CloseCommand();
// Check if there is an SQLConnection object existing for
the
command to use
if (m_Connection == null)
CreateConnection();
// Create the SQLCommand object for the class to use
m_Command = new SqlCommand();
m_Command.Connection = m_Connection;
m_Command.CommandType = CommandType.StoredProcedure;
m_Command.CommandText = StoredProcName;
}

public void AddParameter(string ParamName, object ParamValue) {
// Check if there is an SQLCommand existing before adding
the
parameters. If not, then return an exception.
if (m_Command == null)
throw new NullReferenceException("Command Object is
null.
Please execute CreateCommand first before adding parameters.");

// Add the parameter to the SQLCommand object
SqlParameter parameter;
parameter = m_Command.CreateParameter();
parameter.ParameterName = ParamName;
parameter.Value = ParamValue;
m_Command.Parameters.Add(parameter);
parameter = null;
}

public void ExecuteReader() {
// Check if there is an SQLCommand existing before executing
Data Reader. If not, then return an exception.
if (m_Command == null)
throw new NullReferenceException("Command Object is
null.");
// Check if the connection state of the SQLConnection object
is
open, if not open it.
if (m_Connection.State == ConnectionState.Closed)
m_Connection.Open();
// Close first and dispose the existing data reader is there
is
any
CloseDataReader();
// Create the data reader
m_DataReader = m_Command.ExecuteReader();
}


Code:
~DataAccessLayer() {
Dispose(true);
}


private void CloseConnection()
{
if (m_Connection != null) {
try {
// Check if connection is already closed, if not,
then
close it
if (m_Connection.State != ConnectionState.Closed)
m_Connection.Close(); <<---Error Occurs here
// Dispose the connection object and set it to null
to
release resources used by the object
m_Connection.Dispose();
m_Connection = null;
}
catch {
throw;
}
}
}

private void CloseCommand() {
if (m_Command != null) {
try {
// Dispose the command object and set it to null to
release resources used by the object
m_Command.Dispose();
m_Command = null;
}
catch {
throw;
}
}
}
private void CloseDataReader() {
if (m_DataReader != null) {
try {
// Check if datareader is already closed, if not,
then
close it
if (!m_DataReader.IsClosed)
m_DataReader.Close();
// Set datareader to null
m_DataReader = null;
}
catch {
throw;
}
}
}
private void CloseDataSet() {
if (m_DataSet != null) {
try {
// Dispose object to release resources used
m_DataSet.Dispose();
m_DataSet = null;
}
catch {
throw;
}
}
}

public void Dispose() {
this.Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing) {
// Check to see if Dispose has already been called.
if (!this.m_Disposed) {
if (disposing) {
// Dispose managed resources.
CloseDataReader();
CloseDataSet();
CloseCommand();
CloseConnection();
}
// Release unmanaged resources. If disposing is false,
// only the following code is executed.
}
m_Disposed = true;
}

So Base on this codes, what is the problem?

Thanks in Advanced.


den2005
 

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