473,657 Members | 2,492 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trouble opening a connection to SQL 2000 DB

I'm developing an intranet site in ASP.NET 2.0 but I can't seem to
connect to the DB from within my code. I've created a .vb class that
houses a private Connection() that other functions within the class can
call to connect to the database. In the calling function, I've declared
my connection object and called the "Open" method on the object.
However, when I attempt to execute the stored procedure command by
calling the "ExecuteSca lar" method, I get the following error:

"ExecuteSca lar requires an open and available Connection. The
connection's current state is closed."
Here's the code from my class:
Imports System.Data
Imports System.Data.Sql Client
Namespace Encompass
Public Class EncompassSecuri ty
Public Shared Function GetHRIDByNTUser ID(ByVal strNTUserID) As String
Dim strHRID As String
'Create command object
Dim cmd As New SqlCommand("usp _Get_HRID_By_NT UserID", Connection())
cmd.CommandType = CommandType.Sto redProcedure
'Open DB connection
Dim DBConnection As SqlConnection = Connection()
DBConnection.Op en()
'Input parameters
Dim inNTUserParam As New SqlParameter("@ NT_UserID", SqlDbType.VarCh ar)
inNTUserParam.D irection = ParameterDirect ion.Input
inNTUserParam.V alue = strNTUserID
cmd.Parameters. Add(inNTUserPar am)
'Output parameters
Dim outHRIDParam As New SqlParameter("@ HRID", SqlDbType.Int)
outHRIDParam.Di rection = ParameterDirect ion.Output
cmd.Parameters. Add(outHRIDPara m)
'Run stored procedure
strHRID = cmd.ExecuteScal ar()
Return (strHRID)
'Close DB connection
DBConnection.Cl ose()
End Function
Private Shared Function Connection() As SqlConnection
Dim strConnectionSt ring As String
strConnectionSt ring = ConfigurationMa nager.Connectio nStrings(
"Conn").Connect ionString
Return New SqlConnection(s trConnectionStr ing)
End Function
End Class
End
Namespace
Here's the code from my web.config file:
<?
xml version="1.0"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config. comments usually located in
\Windows\Micros oft.Net\Framewo rk\v2.x\Config
-->
<
configuration
xmlns="http://schemas.microso ft.com/.NetConfigurati on/v2.0">
<
connectionStrin gs>
<
add name="Conn" connectionStrin g="Data Source=ServerNa me;Initial
Catalog=NPASDV; uid=UserName;pa ssword=*******; "
providerName="S ystem.Data.SqlC lient" />
</
connectionStrin gs>
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
Visual Basic options:
Set strict="true" to disallow all data type conversions
where data loss can occur.
Set explicit="true" to force declaration of all variables.
-->
<
roleManager defaultProvider ="AspNetWindows TokenRoleProvid er" />
<
compilation debug="true" strict="false" explicit="true" />
<
pages>
<
namespaces>
<
clear />
<
add namespace="Syst em" />
<
add namespace="Syst em.Collections" />
<
add namespace="Syst em.Collections. Specialized" />
<
add namespace="Syst em.Configuratio n" />
<
add namespace="Syst em.Text" />
<
add namespace="Syst em.Text.Regular Expressions" />
<
add namespace="Syst em.Web" />
<
add namespace="Syst em.Web.Caching" />
<
add namespace="Syst em.Web.SessionS tate" />
<
add namespace="Syst em.Web.Security " />
<
add namespace="Syst em.Web.Profile" />
<
add namespace="Syst em.Web.UI" />
<
add namespace="Syst em.Web.UI.WebCo ntrols" />
<
add namespace="Syst em.Web.UI.WebCo ntrols.WebParts " />
<
add namespace="Syst em.Web.UI.HtmlC ontrols" />
</
namespaces>
</
pages>
<!--
The <authentication > section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<
authentication mode="Windows" />
<!--
The <customErrors > section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnl y" defaultRedirect ="GenericErrorP age.htm">
<error statusCode="403 " redirect="NoAcc ess.htm" />
<error statusCode="404 " redirect="FileN otFound.htm" />
</customErrors>
-->
</
system.web>
</
configuration>
What am I doing wrong? Any help would be most appreciated!!

--
Manuel Garr, MCP

Apr 5 '06 #1
5 1433
You have created a Commad object with a connection object which is not open
yet.

Dim DBConnection As SqlConnection = Connection()
DBConnection.Op en()

Dim cmd As New SqlCommand("usp _Get_HRID_By_NT UserID", DBConnection)
cmd.CommandType = CommandType.Sto redProcedure

"mlg1906" <ml*****@discus sions.microsoft .com> wrote in message
news:86******** *************** ***********@mic rosoft.com...
I'm developing an intranet site in ASP.NET 2.0 but I can't seem to
connect to the DB from within my code. I've created a .vb class that
houses a private Connection() that other functions within the class can
call to connect to the database. In the calling function, I've declared
my connection object and called the "Open" method on the object.
However, when I attempt to execute the stored procedure command by
calling the "ExecuteSca lar" method, I get the following error:

"ExecuteSca lar requires an open and available Connection. The
connection's current state is closed."
Here's the code from my class:
Imports System.Data
Imports System.Data.Sql Client
Namespace Encompass
Public Class EncompassSecuri ty
Public Shared Function GetHRIDByNTUser ID(ByVal strNTUserID) As String
Dim strHRID As String
'Create command object
Dim cmd As New SqlCommand("usp _Get_HRID_By_NT UserID", Connection())
cmd.CommandType = CommandType.Sto redProcedure
'Open DB connection
Dim DBConnection As SqlConnection = Connection()
DBConnection.Op en()
'Input parameters
Dim inNTUserParam As New SqlParameter("@ NT_UserID", SqlDbType.VarCh ar)
inNTUserParam.D irection = ParameterDirect ion.Input
inNTUserParam.V alue = strNTUserID
cmd.Parameters. Add(inNTUserPar am)
'Output parameters
Dim outHRIDParam As New SqlParameter("@ HRID", SqlDbType.Int)
outHRIDParam.Di rection = ParameterDirect ion.Output
cmd.Parameters. Add(outHRIDPara m)
'Run stored procedure
strHRID = cmd.ExecuteScal ar()
Return (strHRID)
'Close DB connection
DBConnection.Cl ose()
End Function
Private Shared Function Connection() As SqlConnection
Dim strConnectionSt ring As String
strConnectionSt ring = ConfigurationMa nager.Connectio nStrings(
"Conn").Connect ionString
Return New SqlConnection(s trConnectionStr ing)
End Function
End Class
End
Namespace
Here's the code from my web.config file:
<?
xml version="1.0"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config. comments usually located in
\Windows\Micros oft.Net\Framewo rk\v2.x\Config
-->
<
configuration
xmlns="http://schemas.microso ft.com/.NetConfigurati on/v2.0">
<
connectionStrin gs>
<
add name="Conn" connectionStrin g="Data Source=ServerNa me;Initial
Catalog=NPASDV; uid=UserName;pa ssword=*******; "
providerName="S ystem.Data.SqlC lient" />
</
connectionStrin gs>
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
Visual Basic options:
Set strict="true" to disallow all data type conversions
where data loss can occur.
Set explicit="true" to force declaration of all variables.
-->
<
roleManager defaultProvider ="AspNetWindows TokenRoleProvid er" />
<
compilation debug="true" strict="false" explicit="true" />
<
pages>
<
namespaces>
<
clear />
<
add namespace="Syst em" />
<
add namespace="Syst em.Collections" />
<
add namespace="Syst em.Collections. Specialized" />
<
add namespace="Syst em.Configuratio n" />
<
add namespace="Syst em.Text" />
<
add namespace="Syst em.Text.Regular Expressions" />
<
add namespace="Syst em.Web" />
<
add namespace="Syst em.Web.Caching" />
<
add namespace="Syst em.Web.SessionS tate" />
<
add namespace="Syst em.Web.Security " />
<
add namespace="Syst em.Web.Profile" />
<
add namespace="Syst em.Web.UI" />
<
add namespace="Syst em.Web.UI.WebCo ntrols" />
<
add namespace="Syst em.Web.UI.WebCo ntrols.WebParts " />
<
add namespace="Syst em.Web.UI.HtmlC ontrols" />
</
namespaces>
</
pages>
<!--
The <authentication > section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<
authentication mode="Windows" />
<!--
The <customErrors > section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnl y" defaultRedirect ="GenericErrorP age.htm">
<error statusCode="403 " redirect="NoAcc ess.htm" />
<error statusCode="404 " redirect="FileN otFound.htm" />
</customErrors>
-->
</
system.web>
</
configuration>
What am I doing wrong? Any help would be most appreciated!!

--
Manuel Garr, MCP

Apr 5 '06 #2

Winista wrote:
You have created a Commad object with a connection object which is not open
yet.

Dim DBConnection As SqlConnection = Connection()
DBConnection.Op en()

Dim cmd As New SqlCommand("usp _Get_HRID_By_NT UserID", DBConnection)
cmd.CommandType = CommandType.Sto redProcedure
A command object can be created without the connection being opened.
However, your code is partially correct. The only thing that needs to
be changed is the call to DBConnection.Op en() should be made right
before the cmd.ExecuteScal ar() call.


"mlg1906" <ml*****@discus sions.microsoft .com> wrote in message
news:86******** *************** ***********@mic rosoft.com...
I'm developing an intranet site in ASP.NET 2.0 but I can't seem to
connect to the DB from within my code. I've created a .vb class that
houses a private Connection() that other functions within the class can
call to connect to the database. In the calling function, I've declared
my connection object and called the "Open" method on the object.
However, when I attempt to execute the stored procedure command by
calling the "ExecuteSca lar" method, I get the following error:

"ExecuteSca lar requires an open and available Connection. The
connection's current state is closed."
Here's the code from my class:
Imports System.Data
Imports System.Data.Sql Client
Namespace Encompass
Public Class EncompassSecuri ty
Public Shared Function GetHRIDByNTUser ID(ByVal strNTUserID) As String
Dim strHRID As String
'Create command object
Dim cmd As New SqlCommand("usp _Get_HRID_By_NT UserID", Connection())
cmd.CommandType = CommandType.Sto redProcedure
'Open DB connection
Dim DBConnection As SqlConnection = Connection()
DBConnection.Op en()
'Input parameters
Dim inNTUserParam As New SqlParameter("@ NT_UserID", SqlDbType.VarCh ar)
inNTUserParam.D irection = ParameterDirect ion.Input
inNTUserParam.V alue = strNTUserID
cmd.Parameters. Add(inNTUserPar am)
'Output parameters
Dim outHRIDParam As New SqlParameter("@ HRID", SqlDbType.Int)
outHRIDParam.Di rection = ParameterDirect ion.Output
cmd.Parameters. Add(outHRIDPara m)
'Run stored procedure
strHRID = cmd.ExecuteScal ar()
Return (strHRID)
'Close DB connection
DBConnection.Cl ose()
End Function
Private Shared Function Connection() As SqlConnection
Dim strConnectionSt ring As String
strConnectionSt ring = ConfigurationMa nager.Connectio nStrings(
"Conn").Connect ionString
Return New SqlConnection(s trConnectionStr ing)
End Function
End Class
End
Namespace
Here's the code from my web.config file:
<?
xml version="1.0"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config. comments usually located in
\Windows\Micros oft.Net\Framewo rk\v2.x\Config
-->
<
configuration
xmlns="http://schemas.microso ft.com/.NetConfigurati on/v2.0">
<
connectionStrin gs>
<
add name="Conn" connectionStrin g="Data Source=ServerNa me;Initial
Catalog=NPASDV; uid=UserName;pa ssword=*******; "
providerName="S ystem.Data.SqlC lient" />
</
connectionStrin gs>
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
Visual Basic options:
Set strict="true" to disallow all data type conversions
where data loss can occur.
Set explicit="true" to force declaration of all variables.
-->
<
roleManager defaultProvider ="AspNetWindows TokenRoleProvid er" />
<
compilation debug="true" strict="false" explicit="true" />
<
pages>
<
namespaces>
<
clear />
<
add namespace="Syst em" />
<
add namespace="Syst em.Collections" />
<
add namespace="Syst em.Collections. Specialized" />
<
add namespace="Syst em.Configuratio n" />
<
add namespace="Syst em.Text" />
<
add namespace="Syst em.Text.Regular Expressions" />
<
add namespace="Syst em.Web" />
<
add namespace="Syst em.Web.Caching" />
<
add namespace="Syst em.Web.SessionS tate" />
<
add namespace="Syst em.Web.Security " />
<
add namespace="Syst em.Web.Profile" />
<
add namespace="Syst em.Web.UI" />
<
add namespace="Syst em.Web.UI.WebCo ntrols" />
<
add namespace="Syst em.Web.UI.WebCo ntrols.WebParts " />
<
add namespace="Syst em.Web.UI.HtmlC ontrols" />
</
namespaces>
</
pages>
<!--
The <authentication > section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<
authentication mode="Windows" />
<!--
The <customErrors > section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnl y" defaultRedirect ="GenericErrorP age.htm">
<error statusCode="403 " redirect="NoAcc ess.htm" />
<error statusCode="404 " redirect="FileN otFound.htm" />
</customErrors>
-->
</
system.web>
</
configuration>
What am I doing wrong? Any help would be most appreciated!!

--
Manuel Garr, MCP


Apr 5 '06 #3
Thanks for you help too!
--
Manuel

"tdavisjr" wrote:

Winista wrote:
You have created a Commad object with a connection object which is not open
yet.

Dim DBConnection As SqlConnection = Connection()
DBConnection.Op en()

Dim cmd As New SqlCommand("usp _Get_HRID_By_NT UserID", DBConnection)
cmd.CommandType = CommandType.Sto redProcedure

A command object can be created without the connection being opened.
However, your code is partially correct. The only thing that needs to
be changed is the call to DBConnection.Op en() should be made right
before the cmd.ExecuteScal ar() call.


"mlg1906" <ml*****@discus sions.microsoft .com> wrote in message
news:86******** *************** ***********@mic rosoft.com...
I'm developing an intranet site in ASP.NET 2.0 but I can't seem to
connect to the DB from within my code. I've created a .vb class that
houses a private Connection() that other functions within the class can
call to connect to the database. In the calling function, I've declared
my connection object and called the "Open" method on the object.
However, when I attempt to execute the stored procedure command by
calling the "ExecuteSca lar" method, I get the following error:

"ExecuteSca lar requires an open and available Connection. The
connection's current state is closed."
Here's the code from my class:
Imports System.Data
Imports System.Data.Sql Client
Namespace Encompass
Public Class EncompassSecuri ty
Public Shared Function GetHRIDByNTUser ID(ByVal strNTUserID) As String
Dim strHRID As String
'Create command object
Dim cmd As New SqlCommand("usp _Get_HRID_By_NT UserID", Connection())
cmd.CommandType = CommandType.Sto redProcedure
'Open DB connection
Dim DBConnection As SqlConnection = Connection()
DBConnection.Op en()
'Input parameters
Dim inNTUserParam As New SqlParameter("@ NT_UserID", SqlDbType.VarCh ar)
inNTUserParam.D irection = ParameterDirect ion.Input
inNTUserParam.V alue = strNTUserID
cmd.Parameters. Add(inNTUserPar am)
'Output parameters
Dim outHRIDParam As New SqlParameter("@ HRID", SqlDbType.Int)
outHRIDParam.Di rection = ParameterDirect ion.Output
cmd.Parameters. Add(outHRIDPara m)
'Run stored procedure
strHRID = cmd.ExecuteScal ar()
Return (strHRID)
'Close DB connection
DBConnection.Cl ose()
End Function
Private Shared Function Connection() As SqlConnection
Dim strConnectionSt ring As String
strConnectionSt ring = ConfigurationMa nager.Connectio nStrings(
"Conn").Connect ionString
Return New SqlConnection(s trConnectionStr ing)
End Function
End Class
End
Namespace
Here's the code from my web.config file:
<?
xml version="1.0"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config. comments usually located in
\Windows\Micros oft.Net\Framewo rk\v2.x\Config
-->
<
configuration
xmlns="http://schemas.microso ft.com/.NetConfigurati on/v2.0">
<
connectionStrin gs>
<
add name="Conn" connectionStrin g="Data Source=ServerNa me;Initial
Catalog=NPASDV; uid=UserName;pa ssword=*******; "
providerName="S ystem.Data.SqlC lient" />
</
connectionStrin gs>
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
Visual Basic options:
Set strict="true" to disallow all data type conversions
where data loss can occur.
Set explicit="true" to force declaration of all variables.
-->
<
roleManager defaultProvider ="AspNetWindows TokenRoleProvid er" />
<
compilation debug="true" strict="false" explicit="true" />
<
pages>
<
namespaces>
<
clear />
<
add namespace="Syst em" />
<
add namespace="Syst em.Collections" />
<
add namespace="Syst em.Collections. Specialized" />
<
add namespace="Syst em.Configuratio n" />
<
add namespace="Syst em.Text" />
<
add namespace="Syst em.Text.Regular Expressions" />
<
add namespace="Syst em.Web" />
<
add namespace="Syst em.Web.Caching" />
<
add namespace="Syst em.Web.SessionS tate" />
<
add namespace="Syst em.Web.Security " />
<
add namespace="Syst em.Web.Profile" />
<
add namespace="Syst em.Web.UI" />
<
add namespace="Syst em.Web.UI.WebCo ntrols" />
<
add namespace="Syst em.Web.UI.WebCo ntrols.WebParts " />
<
add namespace="Syst em.Web.UI.HtmlC ontrols" />
</
namespaces>
</
pages>
<!--

Apr 5 '06 #4

--
Manuel

"Winista" wrote:
You have created a Commad object with a connection object which is not open
yet.

Dim DBConnection As SqlConnection = Connection()
DBConnection.Op en()

Dim cmd As New SqlCommand("usp _Get_HRID_By_NT UserID", DBConnection)
cmd.CommandType = CommandType.Sto redProcedure

"mlg1906" <ml*****@discus sions.microsoft .com> wrote in message
news:86******** *************** ***********@mic rosoft.com...
I'm developing an intranet site in ASP.NET 2.0 but I can't seem to
connect to the DB from within my code. I've created a .vb class that
houses a private Connection() that other functions within the class can
call to connect to the database. In the calling function, I've declared
my connection object and called the "Open" method on the object.
However, when I attempt to execute the stored procedure command by
calling the "ExecuteSca lar" method, I get the following error:

"ExecuteSca lar requires an open and available Connection. The
connection's current state is closed."
Here's the code from my class:
Imports System.Data
Imports System.Data.Sql Client
Namespace Encompass
Public Class EncompassSecuri ty
Public Shared Function GetHRIDByNTUser ID(ByVal strNTUserID) As String
Dim strHRID As String
'Create command object
Dim cmd As New SqlCommand("usp _Get_HRID_By_NT UserID", Connection())
cmd.CommandType = CommandType.Sto redProcedure
'Open DB connection
Dim DBConnection As SqlConnection = Connection()
DBConnection.Op en()
'Input parameters
Dim inNTUserParam As New SqlParameter("@ NT_UserID", SqlDbType.VarCh ar)
inNTUserParam.D irection = ParameterDirect ion.Input
inNTUserParam.V alue = strNTUserID
cmd.Parameters. Add(inNTUserPar am)
'Output parameters
Dim outHRIDParam As New SqlParameter("@ HRID", SqlDbType.Int)
outHRIDParam.Di rection = ParameterDirect ion.Output
cmd.Parameters. Add(outHRIDPara m)
'Run stored procedure
strHRID = cmd.ExecuteScal ar()
Return (strHRID)
'Close DB connection
DBConnection.Cl ose()
End Function
Private Shared Function Connection() As SqlConnection
Dim strConnectionSt ring As String
strConnectionSt ring = ConfigurationMa nager.Connectio nStrings(
"Conn").Connect ionString
Return New SqlConnection(s trConnectionStr ing)
End Function
End Class
End
Namespace
Here's the code from my web.config file:
<?
xml version="1.0"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config. comments usually located in
\Windows\Micros oft.Net\Framewo rk\v2.x\Config
-->
<
configuration
xmlns="http://schemas.microso ft.com/.NetConfigurati on/v2.0">
<
connectionStrin gs>
<
add name="Conn" connectionStrin g="Data Source=ServerNa me;Initial
Catalog=NPASDV; uid=UserName;pa ssword=*******; "
providerName="S ystem.Data.SqlC lient" />
</
connectionStrin gs>
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
Visual Basic options:
Set strict="true" to disallow all data type conversions
where data loss can occur.
Set explicit="true" to force declaration of all variables.
-->
<
roleManager defaultProvider ="AspNetWindows TokenRoleProvid er" />
<
compilation debug="true" strict="false" explicit="true" />
<
pages>
<
namespaces>
<
clear />
<
add namespace="Syst em" />
<
add namespace="Syst em.Collections" />
<
add namespace="Syst em.Collections. Specialized" />
<
add namespace="Syst em.Configuratio n" />
<
add namespace="Syst em.Text" />
<
add namespace="Syst em.Text.Regular Expressions" />
<
add namespace="Syst em.Web" />
<
add namespace="Syst em.Web.Caching" />
<
add namespace="Syst em.Web.SessionS tate" />
<
add namespace="Syst em.Web.Security " />
<
add namespace="Syst em.Web.Profile" />
<
add namespace="Syst em.Web.UI" />
<
add namespace="Syst em.Web.UI.WebCo ntrols" />
<
add namespace="Syst em.Web.UI.WebCo ntrols.WebParts " />
<
add namespace="Syst em.Web.UI.HtmlC ontrols" />
</
namespaces>
</
pages>
<!--
The <authentication > section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<

Apr 5 '06 #5
Thanks so much for your help. It's working now.
--
Manuel

"Winista" wrote:
You have created a Commad object with a connection object which is not open
yet.

Dim DBConnection As SqlConnection = Connection()
DBConnection.Op en()

Dim cmd As New SqlCommand("usp _Get_HRID_By_NT UserID", DBConnection)
cmd.CommandType = CommandType.Sto redProcedure

"mlg1906" <ml*****@discus sions.microsoft .com> wrote in message
news:86******** *************** ***********@mic rosoft.com...
I'm developing an intranet site in ASP.NET 2.0 but I can't seem to
connect to the DB from within my code. I've created a .vb class that
houses a private Connection() that other functions within the class can
call to connect to the database. In the calling function, I've declared
my connection object and called the "Open" method on the object.
However, when I attempt to execute the stored procedure command by
calling the "ExecuteSca lar" method, I get the following error:

"ExecuteSca lar requires an open and available Connection. The
connection's current state is closed."
Here's the code from my class:
Imports System.Data
Imports System.Data.Sql Client
Namespace Encompass
Public Class EncompassSecuri ty
Public Shared Function GetHRIDByNTUser ID(ByVal strNTUserID) As String
Dim strHRID As String
'Create command object
Dim cmd As New SqlCommand("usp _Get_HRID_By_NT UserID", Connection())
cmd.CommandType = CommandType.Sto redProcedure
'Open DB connection
Dim DBConnection As SqlConnection = Connection()
DBConnection.Op en()
'Input parameters
Dim inNTUserParam As New SqlParameter("@ NT_UserID", SqlDbType.VarCh ar)
inNTUserParam.D irection = ParameterDirect ion.Input
inNTUserParam.V alue = strNTUserID
cmd.Parameters. Add(inNTUserPar am)
'Output parameters
Dim outHRIDParam As New SqlParameter("@ HRID", SqlDbType.Int)
outHRIDParam.Di rection = ParameterDirect ion.Output
cmd.Parameters. Add(outHRIDPara m)
'Run stored procedure
strHRID = cmd.ExecuteScal ar()
Return (strHRID)
'Close DB connection
DBConnection.Cl ose()
End Function
Private Shared Function Connection() As SqlConnection
Dim strConnectionSt ring As String
strConnectionSt ring = ConfigurationMa nager.Connectio nStrings(
"Conn").Connect ionString
Return New SqlConnection(s trConnectionStr ing)
End Function
End Class
End
Namespace
Here's the code from my web.config file:
<?
xml version="1.0"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config. comments usually located in
\Windows\Micros oft.Net\Framewo rk\v2.x\Config
-->
<
configuration
xmlns="http://schemas.microso ft.com/.NetConfigurati on/v2.0">
<
connectionStrin gs>
<
add name="Conn" connectionStrin g="Data Source=ServerNa me;Initial
Catalog=NPASDV; uid=UserName;pa ssword=*******; "
providerName="S ystem.Data.SqlC lient" />
</
connectionStrin gs>
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
Visual Basic options:
Set strict="true" to disallow all data type conversions
where data loss can occur.
Set explicit="true" to force declaration of all variables.
-->
<
roleManager defaultProvider ="AspNetWindows TokenRoleProvid er" />
<
compilation debug="true" strict="false" explicit="true" />
<
pages>
<
namespaces>
<
clear />
<
add namespace="Syst em" />
<
add namespace="Syst em.Collections" />
<
add namespace="Syst em.Collections. Specialized" />
<
add namespace="Syst em.Configuratio n" />
<
add namespace="Syst em.Text" />
<
add namespace="Syst em.Text.Regular Expressions" />
<
add namespace="Syst em.Web" />
<
add namespace="Syst em.Web.Caching" />
<
add namespace="Syst em.Web.SessionS tate" />
<
add namespace="Syst em.Web.Security " />
<
add namespace="Syst em.Web.Profile" />
<
add namespace="Syst em.Web.UI" />
<
add namespace="Syst em.Web.UI.WebCo ntrols" />
<
add namespace="Syst em.Web.UI.WebCo ntrols.WebParts " />
<
add namespace="Syst em.Web.UI.HtmlC ontrols" />
</
namespaces>
</
pages>
<!--
The <authentication > section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<

Apr 6 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
4950
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my webserver runs that part of the script (see attached file, snippet.php), though, it doesn't go through. I don't get an error message or anything...it just returns a "1" (whereas it should return a "0") as far as I can tell. I have read the PHP...
15
2799
by: Peroq | last post by:
Hi all I'm not sure ASP is the problem, but my SQL statement seems fine to me. This works fine : strSQL = "SELECT .* FROM _RechPat INNER JOIN NivPatri ON .cod_niv = NivPatri.cod_niv WHERE NivPatri.position=2" set rs = CreateRecordset(strSQL) This doesn't work :
14
3221
by: BlackHawke | last post by:
My Name is Nick Soutter, I am the owner of a small game company, Aepox Games (We're in the middle of a name change from "Lamar Games"), www.lamargames.net. Our first commercial game, Andromeda Online (www.andromedaonline.net) is going into beta soon. It runs on an evaluation edition of SQL Server 2000 (our intention is, when it launches, we earn the money to buy a copy before the evaluation expires).
14
9024
by: jj | last post by:
Is it possible to call a remote php script from within Access? I'm thinking something like: DoCMD... http://www.domain.com/scripts/dataquery.php DoCmd.OpenQuery "update_data", acNormal, acEdit ..... So the PHP script does something on the server database, then when a linked table is viewed within access, the data changes have been made?
6
3784
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory” exception. To get an idea what happens I traced some values using performance monitor and got the following values (for one day): \\FFDS24\ASP.NET Applications(_LM_W3SVC_1_Root_ATV2004)\Errors During Execution: 7 \\FFDS24\ASP.NET Apps v1.1.4322(_LM_W3SVC_1_Root_ATV2004)\Compilations
18
1977
by: Jon Delano | last post by:
Hey all I am building a new computer. I have Windows XP Pro with SP2 and all the updates. I installed VS 2003. Then copied a project from my old computer to the new one. When I try and run the project .. it errors out saying it "sql server does not exist or access denied"
59
7490
by: Rico | last post by:
Hello, I have an application that I'm converting to Access 2003 and SQL Server 2005 Express. The application uses extensive use of DAO and the SEEK method on indexes. I'm having an issue when the recordset opens a table. When I write Set rst = db.OpenRecordset("MyTable",dbOpenTable, dbReadOnly) I get an error. I believe it's invalid operation or invalid parameter, I'm
3
2611
by: lopedon | last post by:
I've got a performance issue in Access 2000 running on Windows 2000. Opening a table local to the MDB takes about 1-2 seconds normally. If I log out of the windows profile that is normally used on the machine and log into another windows profile, the same table in the same MDB file takes 6 seconds to open. I have tried setting the subdatasheet property to and turning autocorrect off, neither one changes anything. Doing a compact/repair...
5
8405
by: kimtherkelsen | last post by:
Hi, I use the System.Data.OleDb.OleDbConnection class to establish a connection to a Oracle 10G database. The dsn connection string I use look like this: dsn=provider="MSDAORA.1";User ID=test;Data Source="172.30.0.25/ JBOS";Password=test; This works fine in Windows XP and Windows server 2003 but I have a customer that try to connect to the database from a Windows 2000
0
8403
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8316
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8833
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8737
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8509
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7345
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6174
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4327
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2735
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.