Solved

vb.net and sql connection query

Posted on 2014-12-02
4
166 Views
Last Modified: 2014-12-02
I am attempting to create a sql connection query into an access database.  This works fine if i give it an absolute path, i am trying to use the datadirectory to call it.  How do i set the appdomain to tell datadirectory to use the applicationdata directory?  I am trying to use the below, but it errors out with "The DataDirectory substitute is not a string."  Basically i have a folder in applicationdata called BMW Maintenance and in that folder is my DB.  I need to connect to it.

AppDomain.CurrentDomain.SetData("DataDirectory", Environment.SpecialFolder.LocalApplicationData)
        Dim con11 As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\BMW Maintenance\BMWMaintenance.accdb")

Open in new window

0
Comment
Question by:derek7467
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 40476108
Try replacing first line with below one.

AppDomain.CurrentDomain.SetData("DataDirectory", Convert.ToString(Environment.SpecialFolder.LocalApplicationData))

Open in new window

0
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 40476113
The error is correct, that's a number (28), try:
AppDomain.CurrentDomain.SetData("DataDirectory", Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData))

Open in new window

0
 

Author Comment

by:derek7467
ID: 40476114
Now i get "invalid value for key in data source"
0
 

Author Closing Comment

by:derek7467
ID: 40476118
thank you
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question