Showing posts with label opening. Show all posts
Showing posts with label opening. Show all posts

Monday, March 26, 2012

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 "ExecuteScalar" method, I get the following error:
"ExecuteScalar 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.SqlClient
Namespace Encompass
Public Class EncompassSecurity
Public Shared Function GetHRIDByNTUserID(ByVal strNTUserID) As String
Dim strHRID As String
'Create command object
Dim cmd As New SqlCommand("usp_Get_HRID_By_NTUserID", Connection())
cmd.CommandType = CommandType.StoredProcedure
'Open DB connection
Dim DBConnection As SqlConnection = Connection()
DBConnection.Open()
'Input parameters
Dim inNTUserParam As New SqlParameter("@dotnet.itags.org.NT_UserID", SqlDbType.VarChar)
inNTUserParam.Direction = ParameterDirection.Input
inNTUserParam.Value = strNTUserID
cmd.Parameters.Add(inNTUserParam)
'Output parameters
Dim outHRIDParam As New SqlParameter("@dotnet.itags.org.HRID", SqlDbType.Int)
outHRIDParam.Direction = ParameterDirection.Output
cmd.Parameters.Add(outHRIDParam)
'Run stored procedure
strHRID = cmd.ExecuteScalar()
Return (strHRID)
'Close DB connection
DBConnection.Close()
End Function
Private Shared Function Connection() As SqlConnection
Dim strConnectionString As String
strConnectionString = ConfigurationManager.ConnectionStrings(
"Conn").ConnectionString
Return New SqlConnection(strConnectionString)
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\Microsoft.Net\Framework\v2.x\Config
-->
<
configuration
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<
connectionStrings>
<
add name="Conn" connectionString="Data Source=ServerName;Initial
Catalog=NPASDV;uid=UserName;password=***
****;"
providerName="System.Data.SqlClient" />
</
connectionStrings>
<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="AspNetWindowsTokenRoleProvider" />
<
compilation debug="true" strict="false" explicit="true" />
<
pages>
<
namespaces>
<
clear />
<
add namespace="System" />
<
add namespace="System.Collections" />
<
add namespace="System.Collections.Specialized" />
<
add namespace="System.Configuration" />
<
add namespace="System.Text" />
<
add namespace="System.Text.RegularExpressions" />
<
add namespace="System.Web" />
<
add namespace="System.Web.Caching" />
<
add namespace="System.Web.SessionState" />
<
add namespace="System.Web.Security" />
<
add namespace="System.Web.Profile" />
<
add namespace="System.Web.UI" />
<
add namespace="System.Web.UI.WebControls" />
<
add namespace="System.Web.UI.WebControls.WebParts" />
<
add namespace="System.Web.UI.HtmlControls" />
</
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="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
</
system.web>
</
configuration>
What am I doing wrong? Any help would be most appreciated!!
Manuel Garr, MCPYou have created a Commad object with a connection object which is not open
yet.
Dim DBConnection As SqlConnection = Connection()
DBConnection.Open()
Dim cmd As New SqlCommand("usp_Get_HRID_By_NTUserID", DBConnection)
cmd.CommandType = CommandType.StoredProcedure
"mlg1906" <mlg1906@.discussions.microsoft.com> wrote in message
news:86C67AB7-8F4E-42A4-B0C8-CB7FC7DE7CD6@.microsoft.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 "ExecuteScalar" method, I get the following error:
> "ExecuteScalar 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.SqlClient
>
> Namespace Encompass
>
> Public Class EncompassSecurity
>
> Public Shared Function GetHRIDByNTUserID(ByVal strNTUserID) As String
>
> Dim strHRID As String
>
> 'Create command object
>
> Dim cmd As New SqlCommand("usp_Get_HRID_By_NTUserID", Connection())
> cmd.CommandType = CommandType.StoredProcedure
>
> 'Open DB connection
>
> Dim DBConnection As SqlConnection = Connection()
> DBConnection.Open()
>
> 'Input parameters
>
> Dim inNTUserParam As New SqlParameter("@.NT_UserID", SqlDbType.VarChar)
> inNTUserParam.Direction = ParameterDirection.Input
>
> inNTUserParam.Value = strNTUserID
>
> cmd.Parameters.Add(inNTUserParam)
>
> 'Output parameters
>
> Dim outHRIDParam As New SqlParameter("@.HRID", SqlDbType.Int)
> outHRIDParam.Direction = ParameterDirection.Output
>
> cmd.Parameters.Add(outHRIDParam)
>
> 'Run stored procedure
> strHRID = cmd.ExecuteScalar()
>
> Return (strHRID)
>
> 'Close DB connection
> DBConnection.Close()
>
> End Function
>
> Private Shared Function Connection() As SqlConnection
>
> Dim strConnectionString As String
> strConnectionString = ConfigurationManager.ConnectionStrings(
>
> "Conn").ConnectionString
>
> Return New SqlConnection(strConnectionString)
>
> 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\Microsoft.Net\Framework\v2.x\Config
>
> -->
>
> <
>
> configuration
> xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
> <
>
> connectionStrings>
> <
>
> add name="Conn" connectionString="Data Source=ServerName;Initial
> Catalog=NPASDV;uid=UserName;password=***
****;"
>
> providerName="System.Data.SqlClient" />
> </
>
> connectionStrings>
>
> <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="AspNetWindowsTokenRoleProvider" />
> <
>
> compilation debug="true" strict="false" explicit="true" />
> <
>
> pages>
> <
>
> namespaces>
> <
>
> clear />
> <
>
> add namespace="System" />
> <
>
> add namespace="System.Collections" />
> <
>
> add namespace="System.Collections.Specialized" />
> <
>
> add namespace="System.Configuration" />
> <
>
> add namespace="System.Text" />
> <
>
> add namespace="System.Text.RegularExpressions" />
> <
>
> add namespace="System.Web" />
> <
>
> add namespace="System.Web.Caching" />
> <
>
> add namespace="System.Web.SessionState" />
> <
>
> add namespace="System.Web.Security" />
> <
>
> add namespace="System.Web.Profile" />
> <
>
> add namespace="System.Web.UI" />
> <
>
> add namespace="System.Web.UI.WebControls" />
> <
>
> add namespace="System.Web.UI.WebControls.WebParts" />
> <
>
> add namespace="System.Web.UI.HtmlControls" />
> </
>
> 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="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
>
> <error statusCode="403" redirect="NoAccess.htm" />
>
> <error statusCode="404" redirect="FileNotFound.htm" />
>
> </customErrors>
>
> -->
> </
>
> system.web>
> </
>
> configuration>
> What am I doing wrong? Any help would be most appreciated!!
>
> --
> Manuel Garr, MCP
>
Winista wrote:
> You have created a Commad object with a connection object which is not ope
n
> yet.
> Dim DBConnection As SqlConnection = Connection()
> DBConnection.Open()
> Dim cmd As New SqlCommand("usp_Get_HRID_By_NTUserID", DBConnection)
> cmd.CommandType = CommandType.StoredProcedure
>
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.Open() should be made right
before the cmd.ExecuteScalar() call.
> "mlg1906" <mlg1906@.discussions.microsoft.com> wrote in message
> news:86C67AB7-8F4E-42A4-B0C8-CB7FC7DE7CD6@.microsoft.com...
--
Manuel
"Winista" wrote:
> You have created a Commad object with a connection object which is not ope
n
> yet.
> Dim DBConnection As SqlConnection = Connection()
> DBConnection.Open()
> Dim cmd As New SqlCommand("usp_Get_HRID_By_NTUserID", DBConnection)
> cmd.CommandType = CommandType.StoredProcedure
> "mlg1906" <mlg1906@.discussions.microsoft.com> wrote in message
> news:86C67AB7-8F4E-42A4-B0C8-CB7FC7DE7CD6@.microsoft.com...
Thanks for you help too!
--
Manuel
"tdavisjr" wrote:
> Winista wrote:
>
> 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.Open() should be made right
> before the cmd.ExecuteScalar() call.
>
>
>
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 ope
n
> yet.
> Dim DBConnection As SqlConnection = Connection()
> DBConnection.Open()
> Dim cmd As New SqlCommand("usp_Get_HRID_By_NTUserID", DBConnection)
> cmd.CommandType = CommandType.StoredProcedure
> "mlg1906" <mlg1906@.discussions.microsoft.com> wrote in message
> news:86C67AB7-8F4E-42A4-B0C8-CB7FC7DE7CD6@.microsoft.com...

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 "ExecuteScalar" method, I get the following error:

"ExecuteScalar 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.SqlClient

Namespace Encompass

Public Class EncompassSecurity

Public Shared Function GetHRIDByNTUserID(ByVal strNTUserID) As String

Dim strHRID As String

'Create command object

Dim cmd As New SqlCommand("usp_Get_HRID_By_NTUserID", Connection())
cmd.CommandType = CommandType.StoredProcedure

'Open DB connection

Dim DBConnection As SqlConnection = Connection()
DBConnection.Open()

'Input parameters

Dim inNTUserParam As New SqlParameter("@dotnet.itags.org.NT_UserID", SqlDbType.VarChar)
inNTUserParam.Direction = ParameterDirection.Input

inNTUserParam.Value = strNTUserID

cmd.Parameters.Add(inNTUserParam)

'Output parameters

Dim outHRIDParam As New SqlParameter("@dotnet.itags.org.HRID", SqlDbType.Int)
outHRIDParam.Direction = ParameterDirection.Output

cmd.Parameters.Add(outHRIDParam)

'Run stored procedure
strHRID = cmd.ExecuteScalar()

Return (strHRID)

'Close DB connection
DBConnection.Close()

End Function

Private Shared Function Connection() As SqlConnection

Dim strConnectionString As String
strConnectionString = ConfigurationManager.ConnectionStrings(

"Conn").ConnectionString

Return New SqlConnection(strConnectionString)

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\Microsoft.Net\Framework\v2.x\Config

--
<

configuration
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<

connectionStrings>
<

add name="Conn" connectionString="Data Source=ServerName;Initial
Catalog=NPASDV;uid=UserName;password=*******;"

providerName="System.Data.SqlClient" />
</

connectionStrings
<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="AspNetWindowsTokenRoleProvider" />
<

compilation debug="true" strict="false" explicit="true" />
<

pages>
<

namespaces>
<

clear />
<

add namespace="System" />
<

add namespace="System.Collections" />
<

add namespace="System.Collections.Specialized" />
<

add namespace="System.Configuration" />
<

add namespace="System.Text" />
<

add namespace="System.Text.RegularExpressions" />
<

add namespace="System.Web" />
<

add namespace="System.Web.Caching" />
<

add namespace="System.Web.SessionState" />
<

add namespace="System.Web.Security" />
<

add namespace="System.Web.Profile" />
<

add namespace="System.Web.UI" />
<

add namespace="System.Web.UI.WebControls" />
<

add namespace="System.Web.UI.WebControls.WebParts" />
<

add namespace="System.Web.UI.HtmlControls" />
</

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="RemoteOnly" defaultRedirect="GenericErrorPage.htm"
<error statusCode="403" redirect="NoAccess.htm" /
<error statusCode="404" redirect="FileNotFound.htm" /
</customErrors
-->
</

system.web>
</

configuration>
What am I doing wrong? Any help would be most appreciated!!

--
Manuel Garr, MCPYou have created a Commad object with a connection object which is not open
yet.

Dim DBConnection As SqlConnection = Connection()
DBConnection.Open()

Dim cmd As New SqlCommand("usp_Get_HRID_By_NTUserID", DBConnection)
cmd.CommandType = CommandType.StoredProcedure

"mlg1906" <mlg1906@.discussions.microsoft.com> wrote in message
news:86C67AB7-8F4E-42A4-B0C8-CB7FC7DE7CD6@.microsoft.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 "ExecuteScalar" method, I get the following error:
> "ExecuteScalar 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.SqlClient
>
> Namespace Encompass
>
> Public Class EncompassSecurity
>
> Public Shared Function GetHRIDByNTUserID(ByVal strNTUserID) As String
>
> Dim strHRID As String
>
> 'Create command object
>
> Dim cmd As New SqlCommand("usp_Get_HRID_By_NTUserID", Connection())
> cmd.CommandType = CommandType.StoredProcedure
>
> 'Open DB connection
>
> Dim DBConnection As SqlConnection = Connection()
> DBConnection.Open()
>
> 'Input parameters
>
> Dim inNTUserParam As New SqlParameter("@.NT_UserID", SqlDbType.VarChar)
> inNTUserParam.Direction = ParameterDirection.Input
>
> inNTUserParam.Value = strNTUserID
>
> cmd.Parameters.Add(inNTUserParam)
>
> 'Output parameters
>
> Dim outHRIDParam As New SqlParameter("@.HRID", SqlDbType.Int)
> outHRIDParam.Direction = ParameterDirection.Output
>
> cmd.Parameters.Add(outHRIDParam)
>
> 'Run stored procedure
> strHRID = cmd.ExecuteScalar()
>
> Return (strHRID)
>
> 'Close DB connection
> DBConnection.Close()
>
> End Function
>
> Private Shared Function Connection() As SqlConnection
>
> Dim strConnectionString As String
> strConnectionString = ConfigurationManager.ConnectionStrings(
>
> "Conn").ConnectionString
>
> Return New SqlConnection(strConnectionString)
>
> 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\Microsoft.Net\Framework\v2.x\Config
>
> -->
>
> <
>
> configuration
> xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
> <
>
> connectionStrings>
> <
>
> add name="Conn" connectionString="Data Source=ServerName;Initial
> Catalog=NPASDV;uid=UserName;password=*******;"
>
> providerName="System.Data.SqlClient" />
> </
>
> connectionStrings>
>
> <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="AspNetWindowsTokenRoleProvider" />
> <
>
> compilation debug="true" strict="false" explicit="true" />
> <
>
> pages>
> <
>
> namespaces>
> <
>
> clear />
> <
>
> add namespace="System" />
> <
>
> add namespace="System.Collections" />
> <
>
> add namespace="System.Collections.Specialized" />
> <
>
> add namespace="System.Configuration" />
> <
>
> add namespace="System.Text" />
> <
>
> add namespace="System.Text.RegularExpressions" />
> <
>
> add namespace="System.Web" />
> <
>
> add namespace="System.Web.Caching" />
> <
>
> add namespace="System.Web.SessionState" />
> <
>
> add namespace="System.Web.Security" />
> <
>
> add namespace="System.Web.Profile" />
> <
>
> add namespace="System.Web.UI" />
> <
>
> add namespace="System.Web.UI.WebControls" />
> <
>
> add namespace="System.Web.UI.WebControls.WebParts" />
> <
>
> add namespace="System.Web.UI.HtmlControls" />
> </
>
> 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="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
>
> <error statusCode="403" redirect="NoAccess.htm" />
>
> <error statusCode="404" redirect="FileNotFound.htm" />
>
> </customErrors>
>
> -->
> </
>
> system.web>
> </
>
> configuration>
> What am I doing wrong? Any help would be most appreciated!!
>
> --
> Manuel Garr, MCP
Winista wrote:
> You have created a Commad object with a connection object which is not open
> yet.
> Dim DBConnection As SqlConnection = Connection()
> DBConnection.Open()
> Dim cmd As New SqlCommand("usp_Get_HRID_By_NTUserID", DBConnection)
> cmd.CommandType = CommandType.StoredProcedure

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.Open() should be made right
before the cmd.ExecuteScalar() call.

> "mlg1906" <mlg1906@.discussions.microsoft.com> wrote in message
> news:86C67AB7-8F4E-42A4-B0C8-CB7FC7DE7CD6@.microsoft.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 "ExecuteScalar" method, I get the following error:
> > "ExecuteScalar 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.SqlClient
> > Namespace Encompass
> > Public Class EncompassSecurity
> > Public Shared Function GetHRIDByNTUserID(ByVal strNTUserID) As String
> > Dim strHRID As String
> > 'Create command object
> > Dim cmd As New SqlCommand("usp_Get_HRID_By_NTUserID", Connection())
> > cmd.CommandType = CommandType.StoredProcedure
> > 'Open DB connection
> > Dim DBConnection As SqlConnection = Connection()
> > DBConnection.Open()
> > 'Input parameters
> > Dim inNTUserParam As New SqlParameter("@.NT_UserID", SqlDbType.VarChar)
> > inNTUserParam.Direction = ParameterDirection.Input
> > inNTUserParam.Value = strNTUserID
> > cmd.Parameters.Add(inNTUserParam)
> > 'Output parameters
> > Dim outHRIDParam As New SqlParameter("@.HRID", SqlDbType.Int)
> > outHRIDParam.Direction = ParameterDirection.Output
> > cmd.Parameters.Add(outHRIDParam)
> > 'Run stored procedure
> > strHRID = cmd.ExecuteScalar()
> > Return (strHRID)
> > 'Close DB connection
> > DBConnection.Close()
> > End Function
> > Private Shared Function Connection() As SqlConnection
> > Dim strConnectionString As String
> > strConnectionString = ConfigurationManager.ConnectionStrings(
> > "Conn").ConnectionString
> > Return New SqlConnection(strConnectionString)
> > 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\Microsoft.Net\Framework\v2.x\Config
> > -->
> > <
> > configuration
> > xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
> > <
> > connectionStrings>
> > <
> > add name="Conn" connectionString="Data Source=ServerName;Initial
> > Catalog=NPASDV;uid=UserName;password=*******;"
> > providerName="System.Data.SqlClient" />
> > </
> > connectionStrings>
> > <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="AspNetWindowsTokenRoleProvider" />
> > <
> > compilation debug="true" strict="false" explicit="true" />
> > <
> > pages>
> > <
> > namespaces>
> > <
> > clear />
> > <
> > add namespace="System" />
> > <
> > add namespace="System.Collections" />
> > <
> > add namespace="System.Collections.Specialized" />
> > <
> > add namespace="System.Configuration" />
> > <
> > add namespace="System.Text" />
> > <
> > add namespace="System.Text.RegularExpressions" />
> > <
> > add namespace="System.Web" />
> > <
> > add namespace="System.Web.Caching" />
> > <
> > add namespace="System.Web.SessionState" />
> > <
> > add namespace="System.Web.Security" />
> > <
> > add namespace="System.Web.Profile" />
> > <
> > add namespace="System.Web.UI" />
> > <
> > add namespace="System.Web.UI.WebControls" />
> > <
> > add namespace="System.Web.UI.WebControls.WebParts" />
> > <
> > add namespace="System.Web.UI.HtmlControls" />
> > </
> > 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="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
> > <error statusCode="403" redirect="NoAccess.htm" />
> > <error statusCode="404" redirect="FileNotFound.htm" />
> > </customErrors>
> > -->
> > </
> > system.web>
> > </
> > configuration>
> > What am I doing wrong? Any help would be most appreciated!!
> > --
> > Manuel Garr, MCP
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.Open()
> > Dim cmd As New SqlCommand("usp_Get_HRID_By_NTUserID", DBConnection)
> > cmd.CommandType = CommandType.StoredProcedure
>
> 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.Open() should be made right
> before the cmd.ExecuteScalar() call.
>
>
> > "mlg1906" <mlg1906@.discussions.microsoft.com> wrote in message
> > news:86C67AB7-8F4E-42A4-B0C8-CB7FC7DE7CD6@.microsoft.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 "ExecuteScalar" method, I get the following error:
> > > > "ExecuteScalar 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.SqlClient
> > > > > Namespace Encompass
> > > > > Public Class EncompassSecurity
> > > > > Public Shared Function GetHRIDByNTUserID(ByVal strNTUserID) As String
> > > > > Dim strHRID As String
> > > > > 'Create command object
> > > > > Dim cmd As New SqlCommand("usp_Get_HRID_By_NTUserID", Connection())
> > > cmd.CommandType = CommandType.StoredProcedure
> > > > > 'Open DB connection
> > > > > Dim DBConnection As SqlConnection = Connection()
> > > DBConnection.Open()
> > > > > 'Input parameters
> > > > > Dim inNTUserParam As New SqlParameter("@.NT_UserID", SqlDbType.VarChar)
> > > inNTUserParam.Direction = ParameterDirection.Input
> > > > > inNTUserParam.Value = strNTUserID
> > > > > cmd.Parameters.Add(inNTUserParam)
> > > > > 'Output parameters
> > > > > Dim outHRIDParam As New SqlParameter("@.HRID", SqlDbType.Int)
> > > outHRIDParam.Direction = ParameterDirection.Output
> > > > > cmd.Parameters.Add(outHRIDParam)
> > > > > 'Run stored procedure
> > > strHRID = cmd.ExecuteScalar()
> > > > > Return (strHRID)
> > > > > 'Close DB connection
> > > DBConnection.Close()
> > > > > End Function
> > > > > Private Shared Function Connection() As SqlConnection
> > > > > Dim strConnectionString As String
> > > strConnectionString = ConfigurationManager.ConnectionStrings(
> > > > > "Conn").ConnectionString
> > > > > Return New SqlConnection(strConnectionString)
> > > > > 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\Microsoft.Net\Framework\v2.x\Config
> > > > > -->
> > > > > <
> > > > > configuration
> > > xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
> > > <
> > > > > connectionStrings>
> > > <
> > > > > add name="Conn" connectionString="Data Source=ServerName;Initial
> > > Catalog=NPASDV;uid=UserName;password=*******;"
> > > > > providerName="System.Data.SqlClient" />
> > > </
> > > > > connectionStrings>
> > > > > <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="AspNetWindowsTokenRoleProvider" />
> > > <
> > > > > compilation debug="true" strict="false" explicit="true" />
> > > <
> > > > > pages>
> > > <
> > > > > namespaces>
> > > <
> > > > > clear />
> > > <
> > > > > add namespace="System" />
> > > <
> > > > > add namespace="System.Collections" />
> > > <
> > > > > add namespace="System.Collections.Specialized" />
> > > <
> > > > > add namespace="System.Configuration" />
> > > <
> > > > > add namespace="System.Text" />
> > > <
> > > > > add namespace="System.Text.RegularExpressions" />
> > > <
> > > > > add namespace="System.Web" />
> > > <
> > > > > add namespace="System.Web.Caching" />
> > > <
> > > > > add namespace="System.Web.SessionState" />
> > > <
> > > > > add namespace="System.Web.Security" />
> > > <
> > > > > add namespace="System.Web.Profile" />
> > > <
> > > > > add namespace="System.Web.UI" />
> > > <
> > > > > add namespace="System.Web.UI.WebControls" />
> > > <
> > > > > add namespace="System.Web.UI.WebControls.WebParts" />
> > > <
> > > > > add namespace="System.Web.UI.HtmlControls" />
> > > </
> > > > > namespaces>
> > > </
> > > > > pages>
> > > <!--
> >
--
Manuel

"Winista" wrote:

> You have created a Commad object with a connection object which is not open
> yet.
> Dim DBConnection As SqlConnection = Connection()
> DBConnection.Open()
> Dim cmd As New SqlCommand("usp_Get_HRID_By_NTUserID", DBConnection)
> cmd.CommandType = CommandType.StoredProcedure
> "mlg1906" <mlg1906@.discussions.microsoft.com> wrote in message
> news:86C67AB7-8F4E-42A4-B0C8-CB7FC7DE7CD6@.microsoft.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 "ExecuteScalar" method, I get the following error:
> > "ExecuteScalar 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.SqlClient
> > Namespace Encompass
> > Public Class EncompassSecurity
> > Public Shared Function GetHRIDByNTUserID(ByVal strNTUserID) As String
> > Dim strHRID As String
> > 'Create command object
> > Dim cmd As New SqlCommand("usp_Get_HRID_By_NTUserID", Connection())
> > cmd.CommandType = CommandType.StoredProcedure
> > 'Open DB connection
> > Dim DBConnection As SqlConnection = Connection()
> > DBConnection.Open()
> > 'Input parameters
> > Dim inNTUserParam As New SqlParameter("@.NT_UserID", SqlDbType.VarChar)
> > inNTUserParam.Direction = ParameterDirection.Input
> > inNTUserParam.Value = strNTUserID
> > cmd.Parameters.Add(inNTUserParam)
> > 'Output parameters
> > Dim outHRIDParam As New SqlParameter("@.HRID", SqlDbType.Int)
> > outHRIDParam.Direction = ParameterDirection.Output
> > cmd.Parameters.Add(outHRIDParam)
> > 'Run stored procedure
> > strHRID = cmd.ExecuteScalar()
> > Return (strHRID)
> > 'Close DB connection
> > DBConnection.Close()
> > End Function
> > Private Shared Function Connection() As SqlConnection
> > Dim strConnectionString As String
> > strConnectionString = ConfigurationManager.ConnectionStrings(
> > "Conn").ConnectionString
> > Return New SqlConnection(strConnectionString)
> > 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\Microsoft.Net\Framework\v2.x\Config
> > -->
> > <
> > configuration
> > xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
> > <
> > connectionStrings>
> > <
> > add name="Conn" connectionString="Data Source=ServerName;Initial
> > Catalog=NPASDV;uid=UserName;password=*******;"
> > providerName="System.Data.SqlClient" />
> > </
> > connectionStrings>
> > <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="AspNetWindowsTokenRoleProvider" />
> > <
> > compilation debug="true" strict="false" explicit="true" />
> > <
> > pages>
> > <
> > namespaces>
> > <
> > clear />
> > <
> > add namespace="System" />
> > <
> > add namespace="System.Collections" />
> > <
> > add namespace="System.Collections.Specialized" />
> > <
> > add namespace="System.Configuration" />
> > <
> > add namespace="System.Text" />
> > <
> > add namespace="System.Text.RegularExpressions" />
> > <
> > add namespace="System.Web" />
> > <
> > add namespace="System.Web.Caching" />
> > <
> > add namespace="System.Web.SessionState" />
> > <
> > add namespace="System.Web.Security" />
> > <
> > add namespace="System.Web.Profile" />
> > <
> > add namespace="System.Web.UI" />
> > <
> > add namespace="System.Web.UI.WebControls" />
> > <
> > add namespace="System.Web.UI.WebControls.WebParts" />
> > <
> > add namespace="System.Web.UI.HtmlControls" />
> > </
> > namespaces>
> > </
> > pages>
> > <!--
> > The <authentication> section enables configuration
> > of the security authentication mode used by
> > ASP.NET to identify an incoming user.
> > -->
> > <
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.Open()
> Dim cmd As New SqlCommand("usp_Get_HRID_By_NTUserID", DBConnection)
> cmd.CommandType = CommandType.StoredProcedure
> "mlg1906" <mlg1906@.discussions.microsoft.com> wrote in message
> news:86C67AB7-8F4E-42A4-B0C8-CB7FC7DE7CD6@.microsoft.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 "ExecuteScalar" method, I get the following error:
> > "ExecuteScalar 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.SqlClient
> > Namespace Encompass
> > Public Class EncompassSecurity
> > Public Shared Function GetHRIDByNTUserID(ByVal strNTUserID) As String
> > Dim strHRID As String
> > 'Create command object
> > Dim cmd As New SqlCommand("usp_Get_HRID_By_NTUserID", Connection())
> > cmd.CommandType = CommandType.StoredProcedure
> > 'Open DB connection
> > Dim DBConnection As SqlConnection = Connection()
> > DBConnection.Open()
> > 'Input parameters
> > Dim inNTUserParam As New SqlParameter("@.NT_UserID", SqlDbType.VarChar)
> > inNTUserParam.Direction = ParameterDirection.Input
> > inNTUserParam.Value = strNTUserID
> > cmd.Parameters.Add(inNTUserParam)
> > 'Output parameters
> > Dim outHRIDParam As New SqlParameter("@.HRID", SqlDbType.Int)
> > outHRIDParam.Direction = ParameterDirection.Output
> > cmd.Parameters.Add(outHRIDParam)
> > 'Run stored procedure
> > strHRID = cmd.ExecuteScalar()
> > Return (strHRID)
> > 'Close DB connection
> > DBConnection.Close()
> > End Function
> > Private Shared Function Connection() As SqlConnection
> > Dim strConnectionString As String
> > strConnectionString = ConfigurationManager.ConnectionStrings(
> > "Conn").ConnectionString
> > Return New SqlConnection(strConnectionString)
> > 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\Microsoft.Net\Framework\v2.x\Config
> > -->
> > <
> > configuration
> > xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
> > <
> > connectionStrings>
> > <
> > add name="Conn" connectionString="Data Source=ServerName;Initial
> > Catalog=NPASDV;uid=UserName;password=*******;"
> > providerName="System.Data.SqlClient" />
> > </
> > connectionStrings>
> > <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="AspNetWindowsTokenRoleProvider" />
> > <
> > compilation debug="true" strict="false" explicit="true" />
> > <
> > pages>
> > <
> > namespaces>
> > <
> > clear />
> > <
> > add namespace="System" />
> > <
> > add namespace="System.Collections" />
> > <
> > add namespace="System.Collections.Specialized" />
> > <
> > add namespace="System.Configuration" />
> > <
> > add namespace="System.Text" />
> > <
> > add namespace="System.Text.RegularExpressions" />
> > <
> > add namespace="System.Web" />
> > <
> > add namespace="System.Web.Caching" />
> > <
> > add namespace="System.Web.SessionState" />
> > <
> > add namespace="System.Web.Security" />
> > <
> > add namespace="System.Web.Profile" />
> > <
> > add namespace="System.Web.UI" />
> > <
> > add namespace="System.Web.UI.WebControls" />
> > <
> > add namespace="System.Web.UI.WebControls.WebParts" />
> > <
> > add namespace="System.Web.UI.HtmlControls" />
> > </
> > namespaces>
> > </
> > pages>
> > <!--
> > The <authentication> section enables configuration
> > of the security authentication mode used by
> > ASP.NET to identify an incoming user.
> > -->
> > <

Trouble opening a asp.net project

Hello,

I've inherited an vs2003 asp.net project from a fellow that had Windows
2000 advanced server as his development machine. As a result he mapped
the project to a web site (mapped to a non-standard port, 87 I think)
instead of mapping it to a virtual directory.

My dev machine is winxppro and my IIS doesn't allow me to create new web
sites. I've tried various techniques to be able to map it to a virtual
directory, but to no avail. I keep getting the error that "The file
path '[Physical Project Path]' does not correspond to the URL '[Project
URL]'. The two need to map to the same server location. HTTP Error 404:
File Not Found."

Is there a definitive guide somewhere that can walk me through the
process of moving the project to a state where I can work on it in
Windows XP?

Or any other advice would also be highly appreciated.

Regards,
RobertLook into the solution and project files and manually change the paths
within each.
--
Christopher A. Reed
"The oxen are slow, but the earth is patient."

"Frank Rizzo" <none@.none.com> wrote in message
news:%230xUfbMjGHA.1324@.TK2MSFTNGP04.phx.gbl...
> Hello,
> I've inherited an vs2003 asp.net project from a fellow that had Windows
> 2000 advanced server as his development machine. As a result he mapped
> the project to a web site (mapped to a non-standard port, 87 I think)
> instead of mapping it to a virtual directory.
> My dev machine is winxppro and my IIS doesn't allow me to create new web
> sites. I've tried various techniques to be able to map it to a virtual
> directory, but to no avail. I keep getting the error that "The file path
> '[Physical Project Path]' does not correspond to the URL '[Project URL]'.
> The two need to map to the same server location. HTTP Error 404: File Not
> Found."
> Is there a definitive guide somewhere that can walk me through the process
> of moving the project to a state where I can work on it in Windows XP?
> Or any other advice would also be highly appreciated.
> Regards,
> Robert

Trouble opening a asp.net project

Hello,
I've inherited an vs2003 asp.net project from a fellow that had Windows
2000 advanced server as his development machine. As a result he mapped
the project to a web site (mapped to a non-standard port, 87 I think)
instead of mapping it to a virtual directory.
My dev machine is winxppro and my IIS doesn't allow me to create new web
sites. I've tried various techniques to be able to map it to a virtual
directory, but to no avail. I keep getting the error that "The file
path '[Physical Project Path]' does not correspond to the URL '[Project
URL]'. The two need to map to the same server location. HTTP Error 404:
File Not Found."
Is there a definitive guide somewhere that can walk me through the
process of moving the project to a state where I can work on it in
Windows XP?
Or any other advice would also be highly appreciated.
Regards,
RobertLook into the solution and project files and manually change the paths
within each.
--
Christopher A. Reed
"The oxen are slow, but the earth is patient."
"Frank Rizzo" <none@.none.com> wrote in message
news:%230xUfbMjGHA.1324@.TK2MSFTNGP04.phx.gbl...
> Hello,
> I've inherited an vs2003 asp.net project from a fellow that had Windows
> 2000 advanced server as his development machine. As a result he mapped
> the project to a web site (mapped to a non-standard port, 87 I think)
> instead of mapping it to a virtual directory.
> My dev machine is winxppro and my IIS doesn't allow me to create new web
> sites. I've tried various techniques to be able to map it to a virtual
> directory, but to no avail. I keep getting the error that "The file path
> '[Physical Project Path]' does not correspond to the URL '[Project URL]'.
> The two need to map to the same server location. HTTP Error 404: File Not
> Found."
> Is there a definitive guide somewhere that can walk me through the process
> of moving the project to a state where I can work on it in Windows XP?
> Or any other advice would also be highly appreciated.
> Regards,
> Robert

Trouble opening an existing web application

I have a copy of an existing project saved to a disk. However, I am unable to open through Visual Studios.Net. I created a new virtual directory through IIS and still cannot get it to open up. I receive an error saying that some of the components are not installed on the specified web server. Any help would be greatly appreciated.Could you please post the error message here?
Visual Studio cannot create or open the application. The likeliest problem is that required components are not installed to the local web server. Run visual studio .NET setup and add the web development tool.