Entity Structure Connection String

I'm not sure about the next issue, so any help would be appreciated. I am working on an application that is related to the MSSQL online database and everything is working fine. The model I'm using is an entity model.

The problem is that I need to change the connection string from the online database to the local one, but I do not know how to do it. Creating a new model is not an option. I tried changing the connection string in web.config, but the errors are the only thing I get ...

This is what I have in web.config:

<connectionStrings> <add name="PravosudnaAkademijaEntities" connectionString="metadata=res://*/PrakModel.csdl|res://*/PrakModel.ssdl|res://*/PrakModel.msl;provider=System.Data.SqlClient;provider connection string='Data Source=HRVOJE-PC;Initial Catalog=pak_baza;Integrated Security=True" providerName="System.Data.EntityClient" /> 

+4
source share
4 answers
 "Data Source=HRVOJE-PC;Initial Catalog=pak_baza;Integrated Security=True" 

This is the part you need to change, itโ€™s just your regular SQL server connection string, HRVOJE-PC is the machine name or IP, pak name of your database. If there is a database on your local computer, you want to replace HRVOJE-PC with localhost .

For examples of SQL Server connection strings, check here

+8
source

Another way is to copy the connection string and make another one for your local one. Open the EDMX properties and select the local connection string from the connectionstrings drop-down list.

+1
source

I don't know if this is recommended, but I think it will work.

There is a constructor in the model.context.cs file:

public ModeEntities (): base ("name = ConnectionStringName_In_Config") {}

if we create another constructor in this file, for example:

public ModeEntities (string connName): base ("name =" + connName) {}

Then we can pass in any connection string that we want to use using the new constructor, assuming that the replaced string has the same database structure as the original EF connection string.

0
source

Source: https://habr.com/ru/post/1342068/


All Articles