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



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" <den2005@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:5940DBE8-71A7-4303-8075-B653075C43D2@xxxxxxxxxxxxxxxx
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

  • 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
    ... I created a new class without the destructor.. ... connection object you use. ... public void CreateConnection{ ... // Close first and dispose the existing data reader is there is ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: C# and GDI Resources
    ... interface use unmanaged resources; i.e. they end up being a wrapper to ... The rule is, if the object has a Dispose or Close method, make SURE you ... your class opens a database connection when an object is instanciated ... method would make sure to Dispose the database connection. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: 2 ways to close a connection
    ... that the fix did not come from calling dispose instead of close. ... > resources used by the object. ... It only closes the connection. ... > Explicitly disposing any object that uses unmanaged resources as soon as you ...
    (microsoft.public.dotnet.languages.vb)
  • 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)