Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 .NET Inside SQL Server (2005)
 The connectionString has not been initialized

Author  Topic 

ajpfister
Starting Member

1 Post

Posted - 2008-05-09 : 11:47:13
I've been developing a web application on my workstation and have been using the code below to query a SQL Server 2005 database. I've always grabbed the connection string information from the web.config and have never had any problems. We have recently upgraded our production environment to a multiple server system that is behind a network load balancer. I'm wondering if this has anything to do with this error message. Please see code below.



Thanks for any help and/or suggestions.
Adam





btnSave_Click Event:


Dim ncVerify As New clsLocVerify(strCity, strState)
Dim verResults As String = ncVerify.VerifyCityState()




clsLocVerify:


Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections.Generic



Public Class clsLocVerify

Private m_City As String
Private m_State As String


Public Sub New(ByVal city As String, ByVal state As String)

m_City = city
m_State = state.Trim().ToUpper()

End Sub





Public Function VerifyCityState() As String

Dim holderCity, holderState As New List(Of String)

Dim strConnString As String
strConnString = System.Configuration.ConfigurationManager.ConnectionStrings("GI_DATA_ConnStr").ConnectionString


If strConnString = "" Then
Return "Unable to Establish Connection with Database"
Exit Function
End If

Dim sqlConn As New SqlConnection()
sqlConn.ConnectionString = strConnString

Dim cmd As New SqlCommand

'****************************************************************check city
cmd.CommandText = "SELECT * FROM us_crush WHERE city = '" & m_City & "'"
cmd.CommandType = CommandType.Text
cmd.Connection = sqlConn


sqlConn.Open()


Dim rdr As SqlDataReader

rdr = cmd.ExecuteReader.



..and so on.
   

- Advertisement -