Solved

vb.net and sql connection query

Posted on 2014-12-02
4
157 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
  • 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
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…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

895 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now