1

I have an ASP.net web application and a database created on another computer. Now I want to run this on my computer.

I have installed SQL Server Express edition and SQL Server Management Studio on my computer and I copied database file to my SQL directory and attached it successfully through SQL Server Management Studio. Applications current connection string looks like this.

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

What do I have to change in this to make it work? FYI I have already copied database to SQL Server Management Studio default installation directory and attached it through SQL Server Management Studio express. Also I connect to SQL Server Management Studio using this server name.

localhost\SQLExpress 

1 Answer 1

1

If you've attached the database to your SQL Server Express instance, then you should be able to use this connection string from now on:

<add name="ASPNETDB" 
     connectionString="Server=.\SQLEXPRESS;Database=ASPNETDB;Integrated Security=True" 
     providerName="System.Data.SqlClient" />

With this, you basically tell your application

  • what server (instance) to connect to (.\SQLEXPRESS)
  • what database to use on the server (ASPNETDB - or whatever name you gave it)
  • to use integrated security (e.g. use your Windows credentials) to log on to SQL Server

That's all you need - SQL Server will handle all the details of dealing with data and transaction log files and all those nitty gritty jobs for you.

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

1 Comment

THANK YOU! Thank you for making me STOP, and evaluate what I was trying to accomplish with my connection string, rather than just copy what had been done before. I backed up the DB from the server, restored to my local express instance, and tried to use the same connection information (except Data Source). Still not sure why the ID and password don't work, but this does. Is ID and password stored at a higher level than the DB?

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.