sql - Relative path connection string vb.net -


possible duplicate:
sql express connection string - relative application location

i have desktop application written in vb.net. app uses sql server express 2008 database (.mdf file). have connection string absolute path this:

dim objconnection new sqlconnection("data source=.\sqlexpress;attachdbfilename=c:\users\pantheo\documents\visual studio 2010\projects\food manager 2012(new)\food manager 2012\food_customerdb.mdf;integrated security=true;user instance=true") 

at pc runs great. if build though , .exe run defferent pc crashes because cannot attach database.

i have tried make relative using connection string:

 dim objconnection new sqlconnection("data source=.\sqlexpress;attachdbfilename=|datadirectory|\food_customerdb.mdf;initial catalog=food_customerdb;integrated security=true;user instance=true") 

with no success. can me? know there ton other answers it, regarding c#, cannot implement them. in advance

the datadirectory value string extracted appdomain.currentdomain property list. in winform application not pre-defined set before opening database.

appdomain.currentdomain.setdata("datadirectory", @"c:\myreadwritefolder") 

then connection string attachdbfilename=|datadirectory|\food_customerdb.mdf should works provided put database there (c:\myreadwritefolder).


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -