0

I've connected a database file (made from SQL Server .mdf) to one of my C# program. But when I take those files to another PC I need to give the connection string again. It's very annoying for me.

Is there any way to get that connection string automatically when I move my project files to another PC?

Any suggestion would be appreciated.

2 Answers 2

1

Yes it is Possible.

Suppose Your Project name is MYproject.

So Please put your database in the Follwing path D:\Projects\MYproject\MYproject.UI\bin\Debug\Database\sql.mdf.

Change your connection string like below

<connectionStrings>
    <add name="DBNAME" providerName="System.Data.SqlServerCe.4.0" connectionString="Data Source=|DataDirectory|\..\..\..\MYproject.UI\bin\Debug\Database\sql.mdf" />
</connectionStrings>
Sign up to request clarification or add additional context in comments.

Comments

0

No I don't think so this is possible.When you transfer you visual studio solution from one pc to another you have to manually change the connection string either in web.config file or in the c# code.There's no way visual studio can automatically detect the database installed on a particular pc and get the connectionstring from it

Comments

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.