Solved

vb.net and sql connection query

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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Suggested Solutions

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

679 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