0

In school I am part of a team of four working to create a GUI to translate the paper records of a made-up company and their functionality to a digital format. We're using an ASP.NET website for this purpose.

Basically we use stored procedures and C# classes to represent the database. The folder we're using for the project contains the site and the libraries in separate folders. If I try to open the site from the folder containing both these elements the site will not run. I want to know if there is some way I can set up a relative path to the database in the Settings.Settings.cs file (or by some other means) of my libraries so I don't have to constantly change the database location for the connection string value every time we move the project.

I suppose I should also mention that the database is in an App_Data folder.

2 Answers 2

1

You want to use Server.MapPath(...)

The MapPath method maps the specified relative or virtual path to the corresponding physical directory on the server.

Sign up to request clarification or add additional context in comments.

1 Comment

Where would I add this method?
0

if your database is in App_Data folder, you should use a connection string like this in web.config:

<add name="Database1ConnectionString1" 
connectionString="Data Source=.\SQLEXPRESS;
AttachDbFilename=|DataDirectory|\Database1.mdf;
Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />

|DataDirectory| will refer to App_Data, wherever you install your web app.

3 Comments

That is how I have my connection string set up. It doesn't do me any good for finding the database from the libraries though (which are in different folders from the site).
In what kind of application do you use those libraries? If they run in an ASP.NET app, they'll be alright. If you're using those libraries in a Console or Windows app, then it have to be made in a different way.
I must've been looking at the wrong file or something. I ended up changing it like you had there and it seems to be working perfectly. I think the initial problem was that I was trying to change the path in the settings file and either it didn't like the pipes or I missed the removal of a quote so it wouldn't accept it. Thanks a lot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.