Solved

vb.net and sql connection query

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

757 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

21 Experts available now in Live!

Get 1:1 Help Now