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

Tech-Archive recommends: Fix windows errors by optimizing your registry



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)" wrote:

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" <den2005@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:3BC55BD8-5D29-41FD-B75A-0CC7380C7A6A@xxxxxxxxxxxxxxxx
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]


[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;
}

[/code]

So Base on this codes, what is the problem?

Thanks in Advanced.


den2005
--
MCP Year 2005, Philippines



.



Relevant Pages

  • Re: VS2005 and SQL Express: Internal .Net Framework Data Provider
    ... connection object you use. ... public void CreateConnection{ ... // Close first and dispose the existing data reader is there ... release resources used by the object ...
    (microsoft.public.dotnet.framework.adonet)
  • VS2005 and SQL Express: Internal .Net Framework Data Provider erro
    ... public void CreateConnection{ ... // Check first if the connection is open, if yes, close it first ... // Close first and dispose the existing data reader is there is ... release resources used by the object ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: VS2005 and SQL Express: Internal .Net Framework Data Provider erro
    ... THe interal connection is underneath the ... public void CreateConnection{ ... // Close first and dispose the existing data reader is there is ... release resources used by the object ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Database Connection
    ... Dispose on your connection instance as soon as you are finished using it, ... Now for my Disposeand destructor, which is a Finalizemethod, I have ... Finalize() on the this.m_conn. ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: Database Connection
    ... Dispose on your connection instance as soon as you are finished using it, ... allow it to go back to the ADO.NET connection pool. ... Now for my Dispose() and destructor, which is a Finalizemethod, I have ...
    (microsoft.public.dotnet.languages.csharp)