ConnectionString property has not been initialized

ali_421

New member
Joined
Jun 17, 2007
Messages
1
Programming Experience
Beginner
i keep gettin the following error message The ConnectionString property has not been initialized

this is my code

Private Sub PopulateAgentListView()
Dim dbConn As OleDb.OleDbConnection
Dim dbCmd As OleDb.OleDbCommand
Dim DataReader As OleDb.OleDbDataReader
Dim SQLText As String = "SELECT * From tblAgent"

dbConn = New OleDb.OleDbConnection
dbCmd = New OleDb.OleDbCommand(SQLText, dbConn)

dbConn.Open()
DataReader = dbCmd.ExecuteReader()

With DataReader
Dim lv1Item As ListViewItem
Do While .Read()
lv1Item = New ListViewItem
lv1Item.Text = DataReader.Item("AgentId")
lv1Item.SubItems.Add(.Item("Agentname".ToString))
lv1Item.SubItems.Add(.Item("Address1").ToString)
lv1Item.SubItems.Add(.Item("Address2".ToString))
lv1Item.SubItems.Add(.Item("Telephonenumber".ToString))
lv1Item.SubItems.Add(.Item("Faxnumber").ToString)
lv1Item.SubItems.Add(.Item("Emailaddress").ToString)


Loop
End With
End Sub

this is my app.config file code
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="Pop_Concert.My.MySettings.databaseConnectionString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\database.mdb"
providerName="System.Data.OleDb" />
</connectionStrings>
<system.diagnostics>
<sources>
<!-- This section defines the logging configuration for My.Application.Log -->
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLog"/>
<!-- Uncomment the below section to write to the Application Event Log -->
<!--<add name="EventLog"/>-->
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSwitch" value="Information" />
</switches>
<sharedListeners>
<add name="FileLog"
type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
initializeData="FileLogWriter"/>
<!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
<!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
</sharedListeners>
</system.diagnostics>
</configuration>

plz help
 
Yeah.. You'd never guess it, but as far as your OleDbConnection is concerned, your connection string hasnt been initialized..

ADO.NET is good, but it isnt a mind reader. If you dont tell it what DB to connect to.. what do you want it to do? Have it guess that one of the strings in the app settings is a connection string and use that?

Put some code in to declare the connection string.. Or better, do your data access the 2.0 way. See the DW2 link in my sig, section on Creating a Simple App.

No, really.. It might sound a bit dumb, like Hello World, but youll be amazed how much hard work youre making your life, just to fill a grid.. ADO's moved on since VB6 :) - what you have there, I could do in.. ~17 mouse clicks and less than a minute. There's a lot of info in the DW2 link, take a read!
 
i guess your code should look like this like System.Data.Cjard said:

' you must define the parameter of oledbConnection constructor
connection = new OledbConnection(connectionString)

hope this would be helpful
 
Back
Top