After making a DataSet and TableAdapter for my access or SQL database file. Where should we place the address of database file. Currently my program works only if database file is in exe folder. What if it is not local?
Printable View
After making a DataSet and TableAdapter for my access or SQL database file. Where should we place the address of database file. Currently my program works only if database file is in exe folder. What if it is not local?
perhaps you can add the file as a resource, or integrate a file dialog or something to load the file.
I guess this is a perfect example for a config file.
Real short example : http://www.ajaxline.com/node/258
Short example: http://www.ezzylearning.com/tutorial.aspx?tid=8067328
All of the writings in config files and cs files about data access (database, dataset, datatable) are done by VS designer. There it puts a "|DataDirectory|" in connection string. In run time this phrase will be mapped to working directory instead of my database file directory.
I should not change the designer-generated code. But I did and replaced "|DataDirectory|" by my database file path. Now program works correctly. But there should be another way to tell the designer to do so, I think!
From a thred in MSDN forum. I learned:
-DataDirectory is a property of ApplicationDeployment in System.Deployment.Application NameSpace. But with only get accessor.
-We should set it when the program starts with
I don't know why it is not documented in MSDN or maybe I just can't find it.Code:AppDomain.CurrentDomain.SetData("DataDirectory", @"C:\DatabasePath...");