Advertisement

04.26.2008 at 05:22PM PDT, ID: 23356424
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

Error Received in Try Statement - 'The Connection Street property has not been initialized

Asked by cedent in Visual Studio, SQL Query Syntax

Tags: , , , ,

Hi There - I keep receiving this error when I attempt to run the attached code - it is in the first Try area - this is the error - the actual code snippet is attached also.  What am I doing wrong/whats missing?

Source Error:
Line 43:         Dim myDS As New DataSet()
Line 44:         Try
Line 45:             LoadSQL.Open()
Line 46:             LoadCommand = New SqlDataAdapter()
Line 47:             LoadCommand.Fill(myDS)
 
Source File: C:\Documents and Settings\carmen.davis\My Documents\Visual Studio 2005\WebSites\NewForceOpsDB\ExecutiveTest.aspx.vb    Line: 45

Stack Trace:
[InvalidOperationException: The ConnectionString property has not been initialized.]
   System.Data.SqlClient.SqlConnection.PermissionDemand() +46
   System.Data.SqlClient.SqlConnectionFactory.PermissionDemand(DbConnection outerConnection) +22
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +89
   System.Data.SqlClient.SqlConnection.Open() +160
   ExecutiveTest.load_dd1() in C:\Documents and Settings\carmen.davis\My Documents\Visual Studio 2005\WebSites\NewForceOpsDB\ExecutiveTest.aspx.vb:45
   ExecutiveTest.initialize_form() in C:\Documents and Settings\carmen.davis\My Documents\Visual Studio 2005\WebSites\NewForceOpsDB\ExecutiveTest.aspx.vb:22
   ExecutiveTest.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\carmen.davis\My Documents\Visual Studio 2005\WebSites\NewForceOpsDB\ExecutiveTest.aspx.vb:17
   System.Web.UI.Control.OnLoad(EventArgs e) +80
   System.Web.UI.Control.LoadRecursive() +49
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3743





Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
 
Partial Class ExecutiveTest
    Inherits System.Web.UI.Page
    Public ForceConn As String
    Public SEL, WHR As New StringBuilder()
    Public LoadSQL As SqlConnection
    Public LoadCommand As SqlDataAdapter
    Public ocaLoad As New DataSet()
    Protected WithEvents SqlStatusCommand As System.Data.SqlClient.SqlCommand
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ForceConn = ConfigurationManager.AppSettings("ForceConnectionString")
        If Not Page.IsPostBack Then
            Call initialize_form()
        End If
    End Sub
    Sub initialize_form()
        'load initial settings for dropdowns
        Call load_dd1()
        ddVPLev6.ClearSelection() : ddVPLev6.Items.Clear()
        ddVPLev6.Items.Insert(0, "Waiting for data...") : ddVPLev6.Enabled = False
        ddDirLev7.ClearSelection() : ddDirLev7.Items.Clear()
        ddDirLev7.Items.Insert(0, "Waiting for data...") : ddDirLev7.Enabled = False
        'clears gridview of all data
        gvData.PageIndex = 0 : gvData.DataSource = Nothing
        gvData.SelectedIndex = -1
    End Sub
    Sub load_dd1()
        Dim LoadSQL As New SqlConnection(ForceConn)
        'input name of store procedure on line below, in quotes
        Dim myCommand As New SqlCommand("sp_getlevel6", LoadSQL)
        myCommand.CommandType = CommandType.StoredProcedure
        With myCommand
            'used to select specific statement
            .Parameters.Add(New SqlParameter("@INQ", SqlDbType.Int)).Value = 1
            'list all variable of stored procedure and default value
            .Parameters.Add(New SqlParameter("@categoryID", SqlDbType.Int)).Value = 0
            .Parameters.Add(New SqlParameter("@parentID", SqlDbType.Int)).Value = 0
        End With
        Dim myDS As New DataSet()
        Try
            LoadSQL.Open()
            LoadCommand = New SqlDataAdapter()
            LoadCommand.Fill(myDS)
            ddSVPLev5.ClearSelection() : ddSVPLev5.Items.Clear()
            ddSVPLev5.DataSource = myDS
            ddSVPLev5.DataBind()
            'optional line, if want to get creative, but not required
            ddSVPLev5.Items.Insert(0, "Select One")
            LoadSQL.Close() : LoadSQL.Dispose()
        Catch SQLexc As SqlException
            testing.Text = SQLexc.ToString
            If LoadSQL.State = ConnectionState.Open Then LoadSQL.Close()
            LoadSQL.Dispose()
            Exit Sub
        End Try
    End Sub
    Sub load_dd2(ByVal parentID As Integer)
        Dim LoadSQL As New SqlConnection(ForceConn)
        'input name of store procedure on line below, in quotes
        Dim myCommand As New SqlCommand("sp_dropdowns", LoadSQL)
        myCommand.CommandType = CommandType.StoredProcedure
        With myCommand
            'used to select specific statement
            .Parameters.Add(New SqlParameter("@INQ", SqlDbType.Int)).Value = 2
            'list all variable of stored procedure and default value
            .Parameters.Add(New SqlParameter("@categoryID", SqlDbType.Int)).Value = 0
            .Parameters.Add(New SqlParameter("@parentID", SqlDbType.Int)).Value = parentID
        End With
        Dim myDS As New DataSet()
        Try
            LoadSQL.Open()
            LoadCommand = New SqlDataAdapter(myCommand)
            LoadCommand.Fill(myDS)
            ddVPLev6.ClearSelection() : ddVPLev6.Items.Clear()
            ddVPLev6.DataSource = myDS
            ddVPLev6.DataBind()
            'optional line, if want to get creative, but not required
            ddVPLev6.Items.Insert(0, "Select One")
            LoadSQL.Close() : LoadSQL.Dispose()
        Catch SQLexc As SqlException
            testing.Text = SQLexc.ToString
            If LoadSQL.State = ConnectionState.Open Then LoadSQL.Close()
            LoadSQL.Dispose()
            Exit Sub
        End Try
    End Sub
    Sub load_dd3(ByVal categoryID As Integer, ByVal parentID As Integer)
        Dim LoadSQL As New SqlConnection(ForceConn)
        'input name of store procedure on line below, in quotes
        Dim myCommand As New SqlCommand("sp_dropdowns", LoadSQL)
        myCommand.CommandType = CommandType.StoredProcedure
        With myCommand
            'used to select specific statement
            .Parameters.Add(New SqlParameter("@INQ", SqlDbType.Int)).Value = 3
            'list all variable of stored procedure and default value
            .Parameters.Add(New SqlParameter("@categoryID", SqlDbType.Int)).Value = categoryID
            .Parameters.Add(New SqlParameter("@parentID", SqlDbType.Int)).Value = parentID
        End With
        Dim myDS As New DataSet()
        Try
            LoadSQL.Open()
            LoadCommand = New SqlDataAdapter(myCommand)
            LoadCommand.Fill(myDS)
            DDDirLev7.ClearSelection() : DDDirLev7.Items.Clear()
            DDDirLev7.DataSource = myDS
            DDDirLev7.DataBind()
            'optional line, if want to get creative, but not required
            DDDirLev7.Items.Insert(0, "Select One")
            LoadSQL.Close() : LoadSQL.Dispose()
        Catch SQLexc As SqlException
            testing.Text = SQLexc.ToString
            If LoadSQL.State = ConnectionState.Open Then LoadSQL.Close()
            LoadSQL.Dispose()
            Exit Sub
        End Try
    End Sub
 
    Protected Sub ddSVPLev5_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddSVPLev5.SelectedIndexChanged
        'reset for list 3 since it's dependent on list 2 which is yet to be chosen
        DDDirLev7.ClearSelection() : DDDirLev7.Items.Clear()
        DDDirLev7.Items.Insert(0, "Waiting for data...") : DDDirLev7.Enabled = False
        'if statement only necessary if using [ddSVPLev5.Items.Insert(0, "Select One")]
        If ddSVPLev5.SelectedIndex = 0 Then
            DDVPLev6.ClearSelection() : DDVPLev6.Items.Clear()
            DDVPLev6.Items.Insert(0, "Waiting for data...") : DDVPLev6.Enabled = False
            Exit Sub
        End If
        DDVPLev6.Enabled = True
        Call load_dd2(CInt(ddSVPLev5.SelectedValue))
    End Sub
    Protected Sub ddVPLev6_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DDVPLev6.SelectedIndexChanged
        'if statement only necessary if using [ddVPLev6.Items.Insert(0, "Select One")]
        If DDVPLev6.SelectedIndex = 0 Then
            DDDirLev7.ClearSelection() : DDDirLev7.Items.Clear()
            DDDirLev7.Items.Insert(0, "Waiting for data...") : DDDirLev7.Enabled = False
            Exit Sub
        End If
        DDDirLev7.Enabled = True
        Call load_dd3(CInt(DDVPLev6.SelectedValue), CInt(ddSVPLev5.SelectedValue))
    End Sub
 
    Protected Sub btnLeaderFilter_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLeaderFilter.Click
        'formats statement pieces
        Call build_query()
        'queries SQL for combined statement
        Call load_data()
    End Sub
    Sub build_query()
        'resets strings to nothing
        SEL.Length = 0 : WHR.Length = 0
        SEL.Append("SELECT column1, column2, column3 FROM testTable")
        'temporary holders for the 3 dropdownlists
        Dim WHR1, WHR2, WHR3 As New StringBuilder()
        WHR1.Length = 0 : WHR2.Length = 0 : WHR3.Length = 0
        'if statement only necessary if using [ddSVPLev5.Items.Insert(0, "Select One")]
        If ddSVPLev5.SelectedIndex > 0 Then
            WHR1.Append("column1 = " & ddSVPLev5.SelectedValue)
        End If
        'if statement only necessary if using [ddVPLev6.Items.Insert(0, "Select One")]
        If DDVPLev6.SelectedIndex > 0 Then
            WHR2.Append("column2 = " & DDVPLev6.SelectedValue)
        End If
        'if statement only necessary if using [ddDirLev7.Items.Insert(0, "Select One")]
        If DDDirLev7.SelectedIndex > 0 Then
            WHR3.Append("column3 = " & DDDirLev7.SelectedValue)
        End If
        If WHR1.Length > 0 Or WHR2.Length > 0 Or WHR3.Length > 0 Then
            WHR.Append(" WHERE ")
            Dim HLD As String = "" 'used for adding AND clause
            If WHR1.Length > 0 Then WHR.Append(WHR1.ToString) : HLD = " AND "
            If WHR2.Length > 0 Then WHR.Append(HLD & WHR2.ToString) : HLD = " AND "
            If WHR3.Length > 0 Then WHR.Append(HLD & WHR3.ToString)
        End If
    End Sub
    Sub load_data()
        Dim LoadSQL As New SqlConnection(ForceConn)
        Dim myCommand As New SqlCommand("SP_Sample", LoadSQL)
        myCommand.CommandType = CommandType.StoredProcedure
        With myCommand
            .Parameters.Add(New SqlParameter("@selectSTR", SqlDbType.NVarChar, 2000)).Value = SEL.ToString
            .Parameters.Add(New SqlParameter("@whereSTR", SqlDbType.NVarChar, 2000)).Value = WHR.ToString
        End With
        Dim myDS As New DataSet()
        Try
            LoadSQL.Open()
            LoadCommand = New SqlDataAdapter(myCommand)
            LoadCommand.Fill(myDS)
            gvData.DataSource = myDS
            gvData.DataBind()
            LoadSQL.Close() : LoadSQL.Dispose()
        Catch SQLexc As SqlException
            testing.Text = SQLexc.ToString
            If LoadSQL.State = ConnectionState.Open Then LoadSQL.Close()
            LoadSQL.Dispose()
            Exit Sub
        End Try
    End Sub
End Class
[+][-]04.26.2008 at 05:47PM PDT, ID: 21447402

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Visual Studio, SQL Query Syntax
Tags: Microsoft, visual studio 2005, visual studio 2005 - vb, VB, the connectionstring property has not been initialized
Sign Up Now!
Solution Provided By: GreenGhost
Participating Experts: 2
Solution Grade: A
 
 
[+][-]04.26.2008 at 10:42PM PDT, ID: 21448280

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.27.2008 at 12:14AM PDT, ID: 21448424

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628