OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Source=|DataDirectory|\ITGS.accdb\ITGS.accdb");
I am using Source=|DataDirectory|\\ITGS.accdb
but for some reason data is not added; but when I specify the full path, the data is added to the database.
Can someone tell why using |DataDirectory|
does not work?
The .NET runtime added support for the DataDirectory macro. This allows Visual Studio to put a special variable in the connection string that will be expanded at run-time.
So you can modify a connection string like this:
"Data Source=.\SQLExpress;AttachDbFileName=|DataDirectory|\data.mdf"
By default, the |DataDirectory| variable will be expanded as follow:
Under the hood, the value for |DataDirectory|simply comes from a property on the app domain. It is possible to change that value and override the default behavior by doing this:
AppDomain.CurrentDomain.SetData("DataDirectory", newpath)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.