Official description of the DataDirectory in the database connection string

Source: Internet
Author: User

Full path vs relative path

One of the reasons why it's hard-to-work with database files before are the full path to the database was serialized In different places. This made it harder to share a project and also to deploy the application. In this version, the. NET runtime added. DATADIRECTORY macro. This allows Visual Studio to put a special variable in the connection string that would be expanded at Run-time. So instead of have a connection string like this:

"Data source=.\sqlexpress; Attachdbfilename=c:\program Files\app\data.mdf "

You can have a connection string like this:

"Data source=.\sqlexpress; attachdbfilename=| Datadirectory|\data.mdf "

This connection string syntax are supported by the SqlClient and OLE DB managed providers.

By default, the | datadirectory| Variable'll be expanded as follow:

-For applications placed in a directory of the user machine, this'll be the app's (. exe) folder.
-For apps running under ClickOnce, this is a special data folder created by ClickOnce
-For Web apps, this would be the App_Data folder

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)

https://blogs.msdn.microsoft.com/smartclientdata/2005/08/26/working-with-local-databases/

Official description of the DataDirectory in the database connection string

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.