Name 'Application' is not declared

yousuf42

Well-known member
Joined
Feb 12, 2006
Messages
101
Programming Experience
1-3
ProtectedConst Oledb Connection String error

ProtectedConst Oledb Connection String error

--------------------------------------------------------------------------------

I have a class module DataAccessLayer and I declared the following in the module.

ProtectedConst OLEDB_CONNECTION_STRING As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Application.StartupPath & "\..\..\Northwind.mdb;" & _
"User Id=admin;Password="

But the above statement appears as error and can't connect to database. anyone can help please?


Thanks in Advance
 
Last edited:
ProtectedConst Oledb Connection String error

I have a class module DataAccessLayer and I declared the following in the module.

ProtectedConst OLEDB_CONNECTION_STRING AsString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Application.StartupPath & "\..\..\Northwind.mdb;" & _
"User Id=admin;Password="

But the above statement appears as error and can't connect to database. anyone can help please?


Thanks in Advance


 
Application class belongs to System.Windows.Forms namespace. I don't think you need it. To get from virtual application path to physical server path you have to use the MapPath method. You can't declare a constant with a variable value (!). Try this:
VB.NET:
Protected dbFileName As String = New IO.FileInfo(IO.Path.Combine(Server.MapPath("."), _
  "..\..\Northwind.mdb")).FullName
 
Protected OLEDB_CONNECTION_STRING As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  "Data Source=" & dbFileName & ";User Id=admin;Password="
 
Back
Top