Solved

vb.net and sql connection query

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

738 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