简体   繁体   中英

Changing Connection Strings in Web.config to access local database instead of online database

(sorry if this is a stupid question) I've recently discontinued a site that I created, as well as the online database.

Recently, I've been interested in working on it locally, so I can learn more about web/databases and the like. The only thing is - I'm not sure how to change the connection string in the web.config from the online connection to the local connection. I've already copied the database to a local server in SQL Management Server Studio.

  • What's the syntax for using a local database as a connection string?

Here is the old online database connection string: There's two connections both to the same database (from what I gather, one is due to the user login, the other is for model creation from database)

<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient"
connectionString="Data Source=tcp:pokemondaycare.database.windows.net,1433;Initial Catalog=PDC-TESTING;Integrated Security=False;User Id=ServerAdmin@pokemondaycare;Password=AzBanks_1;Encrypt=True;TrustServerCertificate=False;MultipleActiveResultSets=True" />
<add name="pokemonDayCareDatabaseEntities" connectionString="metadata=res://*/Models.PDCDataModel.csdl|res://*/Models.PDCDataModel.ssdl|res://*/Models.PDCDataModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=pokemondaycare.database.windows.net;initial catalog=PDC-TESTING;persist security info=True;user id=ServerAdmin;password=AzBanks_1;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" /></connectionStrings>

Here is the local database properties 本地数据库属性

Thanks for any help

This is how it should be (a sample). Check Documentation for more information

<add name="MovieDBContext" 
   connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Movies.mdf;Integrated Security=True" 
   providerName="System.Data.SqlClient" 
/>

Change Data Source to dot . or localhost:

<connectionStrings>
    <add name="DefaultConnection" 
         providerName="System.Data.SqlClient"
         connectionString="Data Source=.;Initial Catalog=PDC-TESTING;
            Integrated Security=False;..." />
</connectionStrings>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM