I'm trying to connect an Access DB with the function beyond. "Invalid path" is the result. My Access database is saved in my project file in the map App_Data. What is the correct path to access the db?
Thanks!
Public Class DataManager
Public Shared Function GetConnection() As OleDbConnection
Dim conString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=~/App_Data/payables.accdb"
Dim con As New OleDbConnection(conString)
Return con
End Function
When using an accdb file (Access 2007 and higher), you need to use the new ACE 12.0 OleDb driver, which isn't installed by default on Windows Servers, so make sure it is available in your production environment. When it is not avalaible, create an mdb file
instead. To reference files in the App_Data folder, the easiest way is to use the DataDirectory Directive:
Dim conString As String = "Provider=Microsoft.ACE.OleDb.12.0;Data Source=|DataDirectory|payables.accdb"
Dim conString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|payables.mdb"
I'm afraid App_Data is a very typical folder that cannot be accessed directly because of its being too special...
There's nothing special about the App_Data folder when you want to access it through code, server.Mappath will work just fine. The only thing special on this folder is that all files are protected form being accessed directly through a web browser....
Decker Dong - MSFT
Try |DataDirectory| instead:
Once again, you're repeating what I already said days ago....
Decker Dong - MSFT
Dim conString AsString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\payables.accdb"
If you would read my previous reply, you'll see that this won't work....
nijs9
Member
8 Points
14 Posts
Creating OLEDB connection with ASP.NET VB
Nov 08, 2011 02:29 PM|LINK
I'm trying to connect an Access DB with the function beyond. "Invalid path" is the result. My Access database is saved in my project file in the map App_Data. What is the correct path to access the db?
Thanks!
Public Class DataManager Public Shared Function GetConnection() As OleDbConnection Dim conString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=~/App_Data/payables.accdb" Dim con As New OleDbConnection(conString) Return con End Functionalex_brambil...
Participant
798 Points
285 Posts
Re: Creating OLEDB connection with ASP.NET VB
Nov 08, 2011 05:59 PM|LINK
I believe the OLEDB provider needs a windows path, e.g. "c:\blah\yourproject\app_data\payables.accdb". Try this...
Dim conString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + server.mappath("~/App_Data/payables.accdb") good luckhans_v
All-Star
35998 Points
6551 Posts
Re: Creating OLEDB connection with ASP.NET VB
Nov 08, 2011 07:07 PM|LINK
When using an accdb file (Access 2007 and higher), you need to use the new ACE 12.0 OleDb driver, which isn't installed by default on Windows Servers, so make sure it is available in your production environment. When it is not avalaible, create an mdb file instead. To reference files in the App_Data folder, the easiest way is to use the DataDirectory Directive:
Dim conString As String = "Provider=Microsoft.ACE.OleDb.12.0;Data Source=|DataDirectory|payables.accdb"
Dim conString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|payables.mdb"
http://www.mikesdotnetting.com/Article/78/AccessDataSource-SqlDataSource-and-connecting-to-Access-databases-in-ASP.NET
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Creating OLEDB connection with ASP.NET VB
Nov 10, 2011 01:28 AM|LINK
No:)
I'm afraid App_Data is a very typical folder that cannot be accessed directly because of its being too special...
Try |DataDirectory| instead:
Dim conString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\payables.accdb"
hans_v
All-Star
35998 Points
6551 Posts
Re: Creating OLEDB connection with ASP.NET VB
Nov 10, 2011 05:40 AM|LINK
There's nothing special about the App_Data folder when you want to access it through code, server.Mappath will work just fine. The only thing special on this folder is that all files are protected form being accessed directly through a web browser....
Once again, you're repeating what I already said days ago....
If you would read my previous reply, you'll see that this won't work....