Mateusz Mateusz - 1 year ago 76
SQL Question

ASP.Net database connection string without drive/user/documents

so I have a question on sql stringconnection. So basically what I have now, is

Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\mateusz\Desktop\RideShare\RideShare\App_Data\RideShare.mdf;Integrated Security=True

While this works on my local machine, if I want to open it somewhere else, I have to change the path up until the \Rideshare folder. Is there a way to provide the string from say

\App_Data\RideShare.mdf;Integrated Security=True

When linking to different pages you can do something like ~/page.aspx, is it possible to do it with the connectionstring?

Answer Source

I am currently working on something similar. The way I achieve this is by setting a relative path like this:

Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\RideShare.mdf;Integrated Security=True
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download