I have an Access database which I created in the App_Data directory. I added the following to the Web.Config file:
<connectionStrings>
<add name="LWAAccessConn" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;DataSource==|DataDirectory|\LWA.mdb;Persist Security Info=True" providerName="System.Data.OleDb"/>
</connectionStrings>
I create the connection as follows (credit to www.moretechtips.net for the following data access code):
Public Sub Init()
If ConnString = "" Then
ConnString = ConfigurationManager.ConnectionStrings(ConnStringID).ConnectionString
Provider = ConfigurationManager.ConnectionStrings(ConnStringID).ProviderName
End If
If Conn Is Nothing Then
PFactory = DbProviderFactories.GetFactory(Provider)
Conn = PFactory.CreateConnection
Conn.ConnectionString = ConnString
Cmd = PFactory.CreateCommand
Cmd.Connection = Conn
End If
End Sub
If I break execution and look at ConnString at this point I see the exact string from the Web.Config file. The "|DataDirectory|" has not been replaced by the actual path to the database. That may be ok, I do not know.
I try to access the database with this code:
Public Function ExecuteNonQuery() As Integer
Dim rows As Integer
Conn.Open()
rows = Cmd.ExecuteNonQuery()
Conn.Close()
Return rows
End Function
At the "Conn.Open()" command I get the following error:
"Can not find installable ISAM".
I am sure I am missing something simple but do not know where to begin. I added a reference to System.Data to my project but that had not affect.
Any help greatly appreciated.
TIA
John