473,761 Members | 9,379 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ExecuteReader requires an open and available Connection.

We are intermitantly receiving this error on our website.
ExecuteReader requires an open and available Connection. The connection's
current state is connecting. Following is the code from the Load event
of the aspx page. The last line is where the error occurs. Does anyone
have any
ideas what is causing this?

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim MyDA As New SqlDataAdapter
Dim MyDT As New DataTable

OpenNCConn()
MyDA = New SqlDataAdapter
MyDT = New DataTable
MyDA.SelectComm and = New SqlCommand("Sel ect ELMAcctEmail from
TFT.dbo.TFTELMC onfig NOLOCK where Acct_Nbr = '" & _
Session("Acct_N br") & "'", NC_Conn)
MyDA.Fill(MyDT)
If (MyDT.Rows.Coun t 0) Then
Session("hasELM ") = True
If Not IsBlank(MyDT.Ro ws(0).Item(0)) Then
Session("ELMAcc tEmail") = Trim(MyDT.Rows( 0).Item(0))
Else
Session("ELMAcc tEmail") = ""
End If
Else
Session("hasELM ") = False
End If
NC_Conn.Close()

OpenNCConn()
MyDA = Nothing
MyDT = Nothing
GC.Collect()
MyDA = New SqlDataAdapter
MyDT = New DataTable
MyDA.SelectComm and = New SqlCommand("Sel ect
HoldCalls,DBMon thlyFee,CallSta tusMenu,BusyNAM essage,PlayResM enu," & _

"PlayAcctResMen u,RecordAll,All ow_Markets,Reve rse,BFIAfterHou rs,DBExtendedDa ta,IdleAgentHol d,SmartAgentRou ting
from TFT.dbo.TFTAcct Cfg NOLOCK where Acct_Nbr = '" & _
Session("Acct_N br") & "'", NC_Conn)
MyDA.SelectComm and.CommandTime out = 0
MyDA.Fill(MyDT)

--
Mike Hollibaugh
Sep 12 '06 #1
6 2213
What is NC_Conn, where and how is it declared? You omitted the most
important part.

Also, I am not clear why you are calling GC.Collect. Leave well enough
alone, and let the GC run when it needs to.

"Mike" <Mi**@discussio ns.microsoft.co mwrote in message
news:70******** *************** ***********@mic rosoft.com...
We are intermitantly receiving this error on our website.
ExecuteReader requires an open and available Connection. The connection's
current state is connecting. Following is the code from the Load event
of the aspx page. The last line is where the error occurs. Does anyone
have any
ideas what is causing this?

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim MyDA As New SqlDataAdapter
Dim MyDT As New DataTable

OpenNCConn()
MyDA = New SqlDataAdapter
MyDT = New DataTable
MyDA.SelectComm and = New SqlCommand("Sel ect ELMAcctEmail from
TFT.dbo.TFTELMC onfig NOLOCK where Acct_Nbr = '" & _
Session("Acct_N br") & "'", NC_Conn)
MyDA.Fill(MyDT)
If (MyDT.Rows.Coun t 0) Then
Session("hasELM ") = True
If Not IsBlank(MyDT.Ro ws(0).Item(0)) Then
Session("ELMAcc tEmail") = Trim(MyDT.Rows( 0).Item(0))
Else
Session("ELMAcc tEmail") = ""
End If
Else
Session("hasELM ") = False
End If
NC_Conn.Close()

OpenNCConn()
MyDA = Nothing
MyDT = Nothing
GC.Collect()
MyDA = New SqlDataAdapter
MyDT = New DataTable
MyDA.SelectComm and = New SqlCommand("Sel ect
HoldCalls,DBMon thlyFee,CallSta tusMenu,BusyNAM essage,PlayResM enu," & _

"PlayAcctResMen u,RecordAll,All ow_Markets,Reve rse,BFIAfterHou rs,DBExtendedDa ta,IdleAgentHol d,SmartAgentRou ting
from TFT.dbo.TFTAcct Cfg NOLOCK where Acct_Nbr = '" & _
Session("Acct_N br") & "'", NC_Conn)
MyDA.SelectComm and.CommandTime out = 0
MyDA.Fill(MyDT)

--
Mike Hollibaugh

Sep 12 '06 #2
It is under the app_code directory in a class. Here is the complete code:

Option Strict Off
Option Explicit On
Imports System.Data
Imports System.Data.Sql Client
Imports System.Runtime. InteropServices .Marshal
Namespace NarrowcastChart
Public Class clsNCIncludes
Public Shared HeaderBackColor As Color = Color.FromArgb( 170, 170, 170)
Public Shared HeaderForeColor As Color = Color.White
Public Shared AltItemBackColo r As Color = Color.White
Public Shared AltItemForeColo r As Color = Color.FromArgb( 0, 51, 102)
Public Shared ItemBackColor As Color = Color.FromArgb( 204, 221, 237)
Public Shared ItemForeColor As Color = Color.FromArgb( 0, 51, 102)
Public Shared Traffic_Conn As New SqlConnection
Public Shared NC_Conn As New SqlConnection
'
'Get BFI Server Name from Registry
'
Public Shared Function GetServer() As String
Dim theServer As String
theServer = GetSetting("Web Dlls", "Config", "Server", "")
If (theServer = "") Then
SaveSetting("We bDlls", "Config", "Server", "GrayMatter ")
theServer = GetSetting("Web Dlls", "Config", "Server", "")
End If
GetServer = theServer
End Function
'
'Get Narrowcast Server Name from Registry
'
Public Shared Function GetNCServer() As String
Dim theServer As String
theServer = GetSetting("Web Dlls", "Config", "NCServer", "")
If (theServer = "") Then
SaveSetting("We bDlls", "Config", "NCServer", "Lenny")
theServer = GetSetting("Web Dlls", "Config", "NCServer", "")
End If
GetNCServer = theServer
End Function
Public Shared Sub OpenConn()
Dim ConnString As String
ConnString = "Integrated security=False; Pooling=False" & _
";Persist Security Info=False" & _
";User ID=sa" & _
";Initial Catalog=Traffic " & _
";Data Source=" & GetServer()
If Not IsNothing(Traff ic_Conn) Then
If (Traffic_Conn.S tate = ConnectionState .Open) Then
Traffic_Conn.Cl ose()
End If
End If
Traffic_Conn = New SqlConnection(C onnString)
Traffic_Conn.Op en()
End Sub
Public Shared Sub OpenNCConn()
Dim ConnString As String
ConnString = "Integrated security=False; Pooling=False" & _
";Persist Security Info=False;" & _
"User ID=NCServices;" & _
"Password=narro wcast;" & _
"Connect Timeout=60;" & _
"Initial Catalog=TFT;" & _
"Data Source=" & GetNCServer()
If Not IsNothing(NC_Co nn) Then
If (NC_Conn.State = ConnectionState .Open) Then
NC_Conn.Close()
End If
End If
NC_Conn = New SqlConnection(C onnString)
NC_Conn.Open()
End Sub
End Class
End Namespace
--
Mike Hollibaugh
"Marina Levit [MVP]" wrote:
What is NC_Conn, where and how is it declared? You omitted the most
important part.

Also, I am not clear why you are calling GC.Collect. Leave well enough
alone, and let the GC run when it needs to.

"Mike" <Mi**@discussio ns.microsoft.co mwrote in message
news:70******** *************** ***********@mic rosoft.com...
We are intermitantly receiving this error on our website.
ExecuteReader requires an open and available Connection. The connection's
current state is connecting. Following is the code from the Load event
of the aspx page. The last line is where the error occurs. Does anyone
have any
ideas what is causing this?

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim MyDA As New SqlDataAdapter
Dim MyDT As New DataTable

OpenNCConn()
MyDA = New SqlDataAdapter
MyDT = New DataTable
MyDA.SelectComm and = New SqlCommand("Sel ect ELMAcctEmail from
TFT.dbo.TFTELMC onfig NOLOCK where Acct_Nbr = '" & _
Session("Acct_N br") & "'", NC_Conn)
MyDA.Fill(MyDT)
If (MyDT.Rows.Coun t 0) Then
Session("hasELM ") = True
If Not IsBlank(MyDT.Ro ws(0).Item(0)) Then
Session("ELMAcc tEmail") = Trim(MyDT.Rows( 0).Item(0))
Else
Session("ELMAcc tEmail") = ""
End If
Else
Session("hasELM ") = False
End If
NC_Conn.Close()

OpenNCConn()
MyDA = Nothing
MyDT = Nothing
GC.Collect()
MyDA = New SqlDataAdapter
MyDT = New DataTable
MyDA.SelectComm and = New SqlCommand("Sel ect
HoldCalls,DBMon thlyFee,CallSta tusMenu,BusyNAM essage,PlayResM enu," & _

"PlayAcctResMen u,RecordAll,All ow_Markets,Reve rse,BFIAfterHou rs,DBExtendedDa ta,IdleAgentHol d,SmartAgentRou ting
from TFT.dbo.TFTAcct Cfg NOLOCK where Acct_Nbr = '" & _
Session("Acct_N br") & "'", NC_Conn)
MyDA.SelectComm and.CommandTime out = 0
MyDA.Fill(MyDT)

--
Mike Hollibaugh


Sep 12 '06 #3
The problem is you are using a Shared SqlConnection. What this means is that
you have ALL your users sharing one connection. However, you are not
synchronizing access to the connection - and multiple users are trying to
use it at once - causing errors.

What you are doing is the the number one no-no when it comes to writing web
based applications that access the database. You do not under any
circumstances create one connection to be used by all users. If you do, you
need to synchronize access to it - but that is going to mean atrocious
performance for your app.

Make sure each user has their own connection. Open it when you need to get
data, get all your data, then close it.

"Mike" <Mi**@discussio ns.microsoft.co mwrote in message
news:AF******** *************** ***********@mic rosoft.com...
It is under the app_code directory in a class. Here is the complete code:

Option Strict Off
Option Explicit On
Imports System.Data
Imports System.Data.Sql Client
Imports System.Runtime. InteropServices .Marshal
Namespace NarrowcastChart
Public Class clsNCIncludes
Public Shared HeaderBackColor As Color = Color.FromArgb( 170, 170,
170)
Public Shared HeaderForeColor As Color = Color.White
Public Shared AltItemBackColo r As Color = Color.White
Public Shared AltItemForeColo r As Color = Color.FromArgb( 0, 51,
102)
Public Shared ItemBackColor As Color = Color.FromArgb( 204, 221,
237)
Public Shared ItemForeColor As Color = Color.FromArgb( 0, 51, 102)
Public Shared Traffic_Conn As New SqlConnection
Public Shared NC_Conn As New SqlConnection
'
'Get BFI Server Name from Registry
'
Public Shared Function GetServer() As String
Dim theServer As String
theServer = GetSetting("Web Dlls", "Config", "Server", "")
If (theServer = "") Then
SaveSetting("We bDlls", "Config", "Server", "GrayMatter ")
theServer = GetSetting("Web Dlls", "Config", "Server", "")
End If
GetServer = theServer
End Function
'
'Get Narrowcast Server Name from Registry
'
Public Shared Function GetNCServer() As String
Dim theServer As String
theServer = GetSetting("Web Dlls", "Config", "NCServer", "")
If (theServer = "") Then
SaveSetting("We bDlls", "Config", "NCServer", "Lenny")
theServer = GetSetting("Web Dlls", "Config", "NCServer", "")
End If
GetNCServer = theServer
End Function
Public Shared Sub OpenConn()
Dim ConnString As String
ConnString = "Integrated security=False; Pooling=False" & _
";Persist Security Info=False" & _
";User ID=sa" & _
";Initial Catalog=Traffic " & _
";Data Source=" & GetServer()
If Not IsNothing(Traff ic_Conn) Then
If (Traffic_Conn.S tate = ConnectionState .Open) Then
Traffic_Conn.Cl ose()
End If
End If
Traffic_Conn = New SqlConnection(C onnString)
Traffic_Conn.Op en()
End Sub
Public Shared Sub OpenNCConn()
Dim ConnString As String
ConnString = "Integrated security=False; Pooling=False" & _
";Persist Security Info=False;" & _
"User ID=NCServices;" & _
"Password=narro wcast;" & _
"Connect Timeout=60;" & _
"Initial Catalog=TFT;" & _
"Data Source=" & GetNCServer()
If Not IsNothing(NC_Co nn) Then
If (NC_Conn.State = ConnectionState .Open) Then
NC_Conn.Close()
End If
End If
NC_Conn = New SqlConnection(C onnString)
NC_Conn.Open()
End Sub
End Class
End Namespace
--
Mike Hollibaugh
"Marina Levit [MVP]" wrote:
>What is NC_Conn, where and how is it declared? You omitted the most
important part.

Also, I am not clear why you are calling GC.Collect. Leave well enough
alone, and let the GC run when it needs to.

"Mike" <Mi**@discussio ns.microsoft.co mwrote in message
news:70******* *************** ************@mi crosoft.com...
We are intermitantly receiving this error on our website.
ExecuteReader requires an open and available Connection. The
connection's
current state is connecting. Following is the code from the Load event
of the aspx page. The last line is where the error occurs. Does
anyone
have any
ideas what is causing this?

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim MyDA As New SqlDataAdapter
Dim MyDT As New DataTable

OpenNCConn()
MyDA = New SqlDataAdapter
MyDT = New DataTable
MyDA.SelectComm and = New SqlCommand("Sel ect ELMAcctEmail from
TFT.dbo.TFTELMC onfig NOLOCK where Acct_Nbr = '" & _
Session("Acct_N br") & "'", NC_Conn)
MyDA.Fill(MyDT)
If (MyDT.Rows.Coun t 0) Then
Session("hasELM ") = True
If Not IsBlank(MyDT.Ro ws(0).Item(0)) Then
Session("ELMAcc tEmail") = Trim(MyDT.Rows( 0).Item(0))
Else
Session("ELMAcc tEmail") = ""
End If
Else
Session("hasELM ") = False
End If
NC_Conn.Close()

OpenNCConn()
MyDA = Nothing
MyDT = Nothing
GC.Collect()
MyDA = New SqlDataAdapter
MyDT = New DataTable
MyDA.SelectComm and = New SqlCommand("Sel ect
HoldCalls,DBMon thlyFee,CallSta tusMenu,BusyNAM essage,PlayResM enu," & _

"PlayAcctResMen u,RecordAll,All ow_Markets,Reve rse,BFIAfterHou rs,DBExtendedDa ta,IdleAgentHol d,SmartAgentRou ting
from TFT.dbo.TFTAcct Cfg NOLOCK where Acct_Nbr = '" & _
Session("Acct_N br") & "'", NC_Conn)
MyDA.SelectComm and.CommandTime out = 0
MyDA.Fill(MyDT)

--
Mike Hollibaugh



Sep 12 '06 #4
Marina, is there a way to do this and leave the code in a class so we don't
have to write the same code over and over again?
--
Mike Hollibaugh
"Marina Levit [MVP]" wrote:
The problem is you are using a Shared SqlConnection. What this means is that
you have ALL your users sharing one connection. However, you are not
synchronizing access to the connection - and multiple users are trying to
use it at once - causing errors.

What you are doing is the the number one no-no when it comes to writing web
based applications that access the database. You do not under any
circumstances create one connection to be used by all users. If you do, you
need to synchronize access to it - but that is going to mean atrocious
performance for your app.

Make sure each user has their own connection. Open it when you need to get
data, get all your data, then close it.

"Mike" <Mi**@discussio ns.microsoft.co mwrote in message
news:AF******** *************** ***********@mic rosoft.com...
It is under the app_code directory in a class. Here is the complete code:

Option Strict Off
Option Explicit On
Imports System.Data
Imports System.Data.Sql Client
Imports System.Runtime. InteropServices .Marshal
Namespace NarrowcastChart
Public Class clsNCIncludes
Public Shared HeaderBackColor As Color = Color.FromArgb( 170, 170,
170)
Public Shared HeaderForeColor As Color = Color.White
Public Shared AltItemBackColo r As Color = Color.White
Public Shared AltItemForeColo r As Color = Color.FromArgb( 0, 51,
102)
Public Shared ItemBackColor As Color = Color.FromArgb( 204, 221,
237)
Public Shared ItemForeColor As Color = Color.FromArgb( 0, 51, 102)
Public Shared Traffic_Conn As New SqlConnection
Public Shared NC_Conn As New SqlConnection
'
'Get BFI Server Name from Registry
'
Public Shared Function GetServer() As String
Dim theServer As String
theServer = GetSetting("Web Dlls", "Config", "Server", "")
If (theServer = "") Then
SaveSetting("We bDlls", "Config", "Server", "GrayMatter ")
theServer = GetSetting("Web Dlls", "Config", "Server", "")
End If
GetServer = theServer
End Function
'
'Get Narrowcast Server Name from Registry
'
Public Shared Function GetNCServer() As String
Dim theServer As String
theServer = GetSetting("Web Dlls", "Config", "NCServer", "")
If (theServer = "") Then
SaveSetting("We bDlls", "Config", "NCServer", "Lenny")
theServer = GetSetting("Web Dlls", "Config", "NCServer", "")
End If
GetNCServer = theServer
End Function
Public Shared Sub OpenConn()
Dim ConnString As String
ConnString = "Integrated security=False; Pooling=False" & _
";Persist Security Info=False" & _
";User ID=sa" & _
";Initial Catalog=Traffic " & _
";Data Source=" & GetServer()
If Not IsNothing(Traff ic_Conn) Then
If (Traffic_Conn.S tate = ConnectionState .Open) Then
Traffic_Conn.Cl ose()
End If
End If
Traffic_Conn = New SqlConnection(C onnString)
Traffic_Conn.Op en()
End Sub
Public Shared Sub OpenNCConn()
Dim ConnString As String
ConnString = "Integrated security=False; Pooling=False" & _
";Persist Security Info=False;" & _
"User ID=NCServices;" & _
"Password=narro wcast;" & _
"Connect Timeout=60;" & _
"Initial Catalog=TFT;" & _
"Data Source=" & GetNCServer()
If Not IsNothing(NC_Co nn) Then
If (NC_Conn.State = ConnectionState .Open) Then
NC_Conn.Close()
End If
End If
NC_Conn = New SqlConnection(C onnString)
NC_Conn.Open()
End Sub
End Class
End Namespace
--
Mike Hollibaugh
"Marina Levit [MVP]" wrote:
What is NC_Conn, where and how is it declared? You omitted the most
important part.

Also, I am not clear why you are calling GC.Collect. Leave well enough
alone, and let the GC run when it needs to.

"Mike" <Mi**@discussio ns.microsoft.co mwrote in message
news:70******** *************** ***********@mic rosoft.com...
We are intermitantly receiving this error on our website.
ExecuteReader requires an open and available Connection. The
connection's
current state is connecting. Following is the code from the Load event
of the aspx page. The last line is where the error occurs. Does
anyone
have any
ideas what is causing this?

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim MyDA As New SqlDataAdapter
Dim MyDT As New DataTable

OpenNCConn()
MyDA = New SqlDataAdapter
MyDT = New DataTable
MyDA.SelectComm and = New SqlCommand("Sel ect ELMAcctEmail from
TFT.dbo.TFTELMC onfig NOLOCK where Acct_Nbr = '" & _
Session("Acct_N br") & "'", NC_Conn)
MyDA.Fill(MyDT)
If (MyDT.Rows.Coun t 0) Then
Session("hasELM ") = True
If Not IsBlank(MyDT.Ro ws(0).Item(0)) Then
Session("ELMAcc tEmail") = Trim(MyDT.Rows( 0).Item(0))
Else
Session("ELMAcc tEmail") = ""
End If
Else
Session("hasELM ") = False
End If
NC_Conn.Close()

OpenNCConn()
MyDA = Nothing
MyDT = Nothing
GC.Collect()
MyDA = New SqlDataAdapter
MyDT = New DataTable
MyDA.SelectComm and = New SqlCommand("Sel ect
HoldCalls,DBMon thlyFee,CallSta tusMenu,BusyNAM essage,PlayResM enu," & _

"PlayAcctResMen u,RecordAll,All ow_Markets,Reve rse,BFIAfterHou rs,DBExtendedDa ta,IdleAgentHol d,SmartAgentRou ting
from TFT.dbo.TFTAcct Cfg NOLOCK where Acct_Nbr = '" & _
Session("Acct_N br") & "'", NC_Conn)
MyDA.SelectComm and.CommandTime out = 0
MyDA.Fill(MyDT)

--
Mike Hollibaugh


Sep 12 '06 #5
What I described has nothing to do with not having the code in a class. In
fact, in .NET all code is in a class.

Not making something shared has nothing to do with how you architect your
application. Your application should still be architected such that either
via inheritence or composition, database access code is encapsulated in one
area.

But again, this has absolutely nothing to do with whether or not a variable
is declared as Shared, I'm not even sure what you are asking.

"Mike" <Mi**@discussio ns.microsoft.co mwrote in message
news:81******** *************** ***********@mic rosoft.com...
Marina, is there a way to do this and leave the code in a class so we
don't
have to write the same code over and over again?
--
Mike Hollibaugh
"Marina Levit [MVP]" wrote:
>The problem is you are using a Shared SqlConnection. What this means is
that
you have ALL your users sharing one connection. However, you are not
synchronizin g access to the connection - and multiple users are trying to
use it at once - causing errors.

What you are doing is the the number one no-no when it comes to writing
web
based applications that access the database. You do not under any
circumstance s create one connection to be used by all users. If you do,
you
need to synchronize access to it - but that is going to mean atrocious
performance for your app.

Make sure each user has their own connection. Open it when you need to
get
data, get all your data, then close it.

"Mike" <Mi**@discussio ns.microsoft.co mwrote in message
news:AF******* *************** ************@mi crosoft.com...
It is under the app_code directory in a class. Here is the complete
code:

Option Strict Off
Option Explicit On
Imports System.Data
Imports System.Data.Sql Client
Imports System.Runtime. InteropServices .Marshal
Namespace NarrowcastChart
Public Class clsNCIncludes
Public Shared HeaderBackColor As Color = Color.FromArgb( 170,
170,
170)
Public Shared HeaderForeColor As Color = Color.White
Public Shared AltItemBackColo r As Color = Color.White
Public Shared AltItemForeColo r As Color = Color.FromArgb( 0, 51,
102)
Public Shared ItemBackColor As Color = Color.FromArgb( 204, 221,
237)
Public Shared ItemForeColor As Color = Color.FromArgb( 0, 51,
102)
Public Shared Traffic_Conn As New SqlConnection
Public Shared NC_Conn As New SqlConnection
'
'Get BFI Server Name from Registry
'
Public Shared Function GetServer() As String
Dim theServer As String
theServer = GetSetting("Web Dlls", "Config", "Server", "")
If (theServer = "") Then
SaveSetting("We bDlls", "Config", "Server", "GrayMatter ")
theServer = GetSetting("Web Dlls", "Config", "Server",
"")
End If
GetServer = theServer
End Function
'
'Get Narrowcast Server Name from Registry
'
Public Shared Function GetNCServer() As String
Dim theServer As String
theServer = GetSetting("Web Dlls", "Config", "NCServer", "")
If (theServer = "") Then
SaveSetting("We bDlls", "Config", "NCServer", "Lenny")
theServer = GetSetting("Web Dlls", "Config", "NCServer",
"")
End If
GetNCServer = theServer
End Function
Public Shared Sub OpenConn()
Dim ConnString As String
ConnString = "Integrated security=False; Pooling=False" & _
";Persist Security Info=False" & _
";User ID=sa" & _
";Initial Catalog=Traffic " & _
";Data Source=" & GetServer()
If Not IsNothing(Traff ic_Conn) Then
If (Traffic_Conn.S tate = ConnectionState .Open) Then
Traffic_Conn.Cl ose()
End If
End If
Traffic_Conn = New SqlConnection(C onnString)
Traffic_Conn.Op en()
End Sub
Public Shared Sub OpenNCConn()
Dim ConnString As String
ConnString = "Integrated security=False; Pooling=False" & _
";Persist Security Info=False;" & _
"User ID=NCServices;" & _
"Password=narro wcast;" & _
"Connect Timeout=60;" & _
"Initial Catalog=TFT;" & _
"Data Source=" & GetNCServer()
If Not IsNothing(NC_Co nn) Then
If (NC_Conn.State = ConnectionState .Open) Then
NC_Conn.Close()
End If
End If
NC_Conn = New SqlConnection(C onnString)
NC_Conn.Open()
End Sub
End Class
End Namespace
--
Mike Hollibaugh
"Marina Levit [MVP]" wrote:

What is NC_Conn, where and how is it declared? You omitted the most
important part.

Also, I am not clear why you are calling GC.Collect. Leave well enough
alone, and let the GC run when it needs to.

"Mike" <Mi**@discussio ns.microsoft.co mwrote in message
news:70******* *************** ************@mi crosoft.com...
We are intermitantly receiving this error on our website.
ExecuteReader requires an open and available Connection. The
connection's
current state is connecting. Following is the code from the Load
event
of the aspx page. The last line is where the error occurs. Does
anyone
have any
ideas what is causing this?

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim MyDA As New SqlDataAdapter
Dim MyDT As New DataTable

OpenNCConn()
MyDA = New SqlDataAdapter
MyDT = New DataTable
MyDA.SelectComm and = New SqlCommand("Sel ect ELMAcctEmail from
TFT.dbo.TFTELMC onfig NOLOCK where Acct_Nbr = '" & _
Session("Acct_N br") & "'", NC_Conn)
MyDA.Fill(MyDT)
If (MyDT.Rows.Coun t 0) Then
Session("hasELM ") = True
If Not IsBlank(MyDT.Ro ws(0).Item(0)) Then
Session("ELMAcc tEmail") = Trim(MyDT.Rows( 0).Item(0))
Else
Session("ELMAcc tEmail") = ""
End If
Else
Session("hasELM ") = False
End If
NC_Conn.Close()

OpenNCConn()
MyDA = Nothing
MyDT = Nothing
GC.Collect()
MyDA = New SqlDataAdapter
MyDT = New DataTable
MyDA.SelectComm and = New SqlCommand("Sel ect
HoldCalls,DBMon thlyFee,CallSta tusMenu,BusyNAM essage,PlayResM enu," &
_

"PlayAcctResMen u,RecordAll,All ow_Markets,Reve rse,BFIAfterHou rs,DBExtendedDa ta,IdleAgentHol d,SmartAgentRou ting
from TFT.dbo.TFTAcct Cfg NOLOCK where Acct_Nbr = '" & _
Session("Acct_N br") & "'", NC_Conn)
MyDA.SelectComm and.CommandTime out = 0
MyDA.Fill(MyDT)

--
Mike Hollibaugh



Sep 12 '06 #6
Thanks for your responses Marina. I will remove the sharred items
and see how that works.
--
Mike Hollibaugh
"Marina Levit [MVP]" wrote:
What I described has nothing to do with not having the code in a class. In
fact, in .NET all code is in a class.

Not making something shared has nothing to do with how you architect your
application. Your application should still be architected such that either
via inheritence or composition, database access code is encapsulated in one
area.

But again, this has absolutely nothing to do with whether or not a variable
is declared as Shared, I'm not even sure what you are asking.

"Mike" <Mi**@discussio ns.microsoft.co mwrote in message
news:81******** *************** ***********@mic rosoft.com...
Marina, is there a way to do this and leave the code in a class so we
don't
have to write the same code over and over again?
--
Mike Hollibaugh
"Marina Levit [MVP]" wrote:
The problem is you are using a Shared SqlConnection. What this means is
that
you have ALL your users sharing one connection. However, you are not
synchronizing access to the connection - and multiple users are trying to
use it at once - causing errors.

What you are doing is the the number one no-no when it comes to writing
web
based applications that access the database. You do not under any
circumstances create one connection to be used by all users. If you do,
you
need to synchronize access to it - but that is going to mean atrocious
performance for your app.

Make sure each user has their own connection. Open it when you need to
get
data, get all your data, then close it.

"Mike" <Mi**@discussio ns.microsoft.co mwrote in message
news:AF******** *************** ***********@mic rosoft.com...
It is under the app_code directory in a class. Here is the complete
code:

Option Strict Off
Option Explicit On
Imports System.Data
Imports System.Data.Sql Client
Imports System.Runtime. InteropServices .Marshal
Namespace NarrowcastChart
Public Class clsNCIncludes
Public Shared HeaderBackColor As Color = Color.FromArgb( 170,
170,
170)
Public Shared HeaderForeColor As Color = Color.White
Public Shared AltItemBackColo r As Color = Color.White
Public Shared AltItemForeColo r As Color = Color.FromArgb( 0, 51,
102)
Public Shared ItemBackColor As Color = Color.FromArgb( 204, 221,
237)
Public Shared ItemForeColor As Color = Color.FromArgb( 0, 51,
102)
Public Shared Traffic_Conn As New SqlConnection
Public Shared NC_Conn As New SqlConnection
'
'Get BFI Server Name from Registry
'
Public Shared Function GetServer() As String
Dim theServer As String
theServer = GetSetting("Web Dlls", "Config", "Server", "")
If (theServer = "") Then
SaveSetting("We bDlls", "Config", "Server", "GrayMatter ")
theServer = GetSetting("Web Dlls", "Config", "Server",
"")
End If
GetServer = theServer
End Function
'
'Get Narrowcast Server Name from Registry
'
Public Shared Function GetNCServer() As String
Dim theServer As String
theServer = GetSetting("Web Dlls", "Config", "NCServer", "")
If (theServer = "") Then
SaveSetting("We bDlls", "Config", "NCServer", "Lenny")
theServer = GetSetting("Web Dlls", "Config", "NCServer",
"")
End If
GetNCServer = theServer
End Function
Public Shared Sub OpenConn()
Dim ConnString As String
ConnString = "Integrated security=False; Pooling=False" & _
";Persist Security Info=False" & _
";User ID=sa" & _
";Initial Catalog=Traffic " & _
";Data Source=" & GetServer()
If Not IsNothing(Traff ic_Conn) Then
If (Traffic_Conn.S tate = ConnectionState .Open) Then
Traffic_Conn.Cl ose()
End If
End If
Traffic_Conn = New SqlConnection(C onnString)
Traffic_Conn.Op en()
End Sub
Public Shared Sub OpenNCConn()
Dim ConnString As String
ConnString = "Integrated security=False; Pooling=False" & _
";Persist Security Info=False;" & _
"User ID=NCServices;" & _
"Password=narro wcast;" & _
"Connect Timeout=60;" & _
"Initial Catalog=TFT;" & _
"Data Source=" & GetNCServer()
If Not IsNothing(NC_Co nn) Then
If (NC_Conn.State = ConnectionState .Open) Then
NC_Conn.Close()
End If
End If
NC_Conn = New SqlConnection(C onnString)
NC_Conn.Open()
End Sub
End Class
End Namespace
--
Mike Hollibaugh
"Marina Levit [MVP]" wrote:

What is NC_Conn, where and how is it declared? You omitted the most
important part.

Also, I am not clear why you are calling GC.Collect. Leave well enough
alone, and let the GC run when it needs to.

"Mike" <Mi**@discussio ns.microsoft.co mwrote in message
news:70******** *************** ***********@mic rosoft.com...
We are intermitantly receiving this error on our website.
ExecuteReader requires an open and available Connection. The
connection's
current state is connecting. Following is the code from the Load
event
of the aspx page. The last line is where the error occurs. Does
anyone
have any
ideas what is causing this?

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim MyDA As New SqlDataAdapter
Dim MyDT As New DataTable

OpenNCConn()
MyDA = New SqlDataAdapter
MyDT = New DataTable
MyDA.SelectComm and = New SqlCommand("Sel ect ELMAcctEmail from
TFT.dbo.TFTELMC onfig NOLOCK where Acct_Nbr = '" & _
Session("Acct_N br") & "'", NC_Conn)
MyDA.Fill(MyDT)
If (MyDT.Rows.Coun t 0) Then
Session("hasELM ") = True
If Not IsBlank(MyDT.Ro ws(0).Item(0)) Then
Session("ELMAcc tEmail") = Trim(MyDT.Rows( 0).Item(0))
Else
Session("ELMAcc tEmail") = ""
End If
Else
Session("hasELM ") = False
End If
NC_Conn.Close()

OpenNCConn()
MyDA = Nothing
MyDT = Nothing
GC.Collect()
MyDA = New SqlDataAdapter
MyDT = New DataTable
MyDA.SelectComm and = New SqlCommand("Sel ect
HoldCalls,DBMon thlyFee,CallSta tusMenu,BusyNAM essage,PlayResM enu," &
_

"PlayAcctResMen u,RecordAll,All ow_Markets,Reve rse,BFIAfterHou rs,DBExtendedDa ta,IdleAgentHol d,SmartAgentRou ting
from TFT.dbo.TFTAcct Cfg NOLOCK where Acct_Nbr = '" & _
Session("Acct_N br") & "'", NC_Conn)
MyDA.SelectComm and.CommandTime out = 0
MyDA.Fill(MyDT)

--
Mike Hollibaugh



Sep 12 '06 #7

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

Similar topics

1
4913
by: MSNEWS | last post by:
I get this error when trying to run a SQL command, maybe my program is silly, I'm pretty new at this : Additional information: SqlCommand.Prepare method requires all variable length parameters to have an explicitly set non-zero Size. selcmd.Connection = con selcmd.CommandText = "SELECT identcol FROM resumeconv_directories"
0
2534
by: James Hokes | last post by:
Hi All, We're using the 1.1. Framework against SQL Server 2000, and are having a strange issue where we don't get errors back from the stored procedure, i.e. the exception never gets thrown. The scenario is this: 1.) Set up SqlConnection and SqlCommand 2.) Set SqlDataReader equal to the return value from SqlCommand.ExecuteReader
6
4499
by: karim | last post by:
I have an asp.net page that stopped running properly giving the error below. The app uses a SQL Server 2000 on another server. Enterprise Manager and Query analyzer on the web server can connect to that sql server just fine and run queries. I rebooted the web server and made aspnet member of the admin group. I don't know why the error mentions open connections if I can open several query anaylzer windows using the same sql server...
2
11600
by: MattB | last post by:
I'm trying to implement an example I found for displaying images stored in a SQL database. The example code looks like this (in page_load): Dim connstr As String = "Integrated Security=SSPI;Initial Catalog=Northwind;Data Source=SERVER\netsdk" Dim cnn As New SqlConnection(connstr) Dim cmd As New SqlCommand ("select * from images where id=" & Request.QueryString("id"), cnn) cnn.Open() Dim dr As SqlDataReader = cmd.ExecuteReader()
2
14237
by: CJM | last post by:
I'm not sure where I cam going wrong here... I'm getting the runtime error above, but my code seems reasonable. Am I missing something? Code Snippet: oConn = New SqlConnection oConn.ConnectionString = "Data Source=MyServer;Initial Catalog=TADB;User Id=TADB;Password=xxx;" oCmd = New SqlCommand("Exec TA_GetTADetails " & txtTANumber.Text) oConn.Open()
4
4070
by: phil | last post by:
Hi, With the code below, i get the error: ExecuteReader: Connection property has not been initialized. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: ExecuteReader: Connection property has not been initialized.
1
4733
by: fniles | last post by:
I am using OLEDBDataReader to read from an Access database. I have 4 data source where I get my data from, and each data source is in its own thread. When receiving data, if it is a new commodity I am need to read from the database. Since I can receive data from different data source at the same time, it is possible that I read from the database at the same time.
2
17872
by: Martin Z | last post by:
I'm using the TableAdapterHelper to set the connection and transaction properties on all the commands of all my typed table adapters.... I've checked at the time of the error and all the commands have their Transaction property set. But I still get this error when I call... documentTA.Update(documentDS.Document); "ExecuteReader requires the command to have a transaction when the connection assigned to the command is in a pending local...
7
13585
by: fniles | last post by:
I am using VB.Net 2003 and MS Access (connecting using OleDBConnection). I read using DataAdapter and DataSet, not DataReader. When many people try to access the database at the same time, I get the error "ExecuteReader requires an open and available Connection. The connection's current state is Open, Executing." I do not use ExecuteReader, why the error says ExecuteReader. What does it mean ? When I get this error, is there a way for me...
0
9522
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9336
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
10111
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
9765
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8770
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 project—planning, coding, testing, and deployment—without 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...
0
5215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5364
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3866
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
3
3446
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.