ConnnectionString Problem

  • Thread starter Thread starter Roshawn
  • Start date Start date
R

Roshawn

Hi,

I have a Windows application that makes use of a config file. The config
file contains my connection string to an Access database. In my code-behind
file I've created a variable (ocon) that retrieves this data from the config
file using ConfigurationSettings.AppSettings.

From the code-behind file I call a method from an external .dll file that
accepts a valid connection string. I supply my variable (ocon) to the
method. However, when the code is run, I'm told that the ConnectionString
property of my connection object is not initialized. Here's my code:

Public Class Form1

'Windows Forms Designer Generated Code

Dim ocon as String = ConfigurationSettings.AppSettings("constr")
Private AG AS DataSet

Private Sub Form1_Load()
Dim adt as New AllData()
AG = adt.GetData(ocon)
End Sub

..................................

Namespace MAC
Public Class AllData
Dim ds as New DataSet()
Dim conn as OleDbConnection

Public Function GetData(ByVal constr As String) As DataSet
conn = New OleDbConnection(constr)
conn.Open()
'a few helper functions are placed here
conn.Close()
End Function
End Class

I've run the app dozens of times and the same error persists. Is there
something that I'm doing wrong? Is it possible to read from the config file
and pass the desired data to an external .dll file?

Thanks,
Roshawn
 
Yes I did. It is set like this:
<configuration>
<appSettings>
<add key="constr" value="Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=E:\AGG.mdb" />
</appSettings>
</configuration>

For some strange reason or another, it doesn't work.
 
Back
Top