5

I'm not sure what to regarding the following problem so any help would be appreciated. I'm working on an application that is connected to the online MSSQL database and everything is working fine. The model I'm using is entity model.

The problem is that I have to change the connection string from the online database to the local one, but I don't know how. Creating new model isn't an option. I tried changing the connection string in web.config, but 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=MY-PC;Initial Catalog=pak_baza;Integrated Security=True" providerName="System.Data.EntityClient" />

1
  • which online Mssql hosting service you are using and how to connect with online because in my case it shows error while online localhost work fine Commented Mar 11, 2018 at 15:13

4 Answers 4

9
"Data Source=HRVOJE-PC;Initial Catalog=pak_baza;Integrated Security=True"

This is the part you should be changing, it's just your regular SQL server connection string, HRVOJE-PC is the machine name or IP, pak the name of your database. If you have a DB on your local machine you want to replace HRVOJE-PC with localhost.

For examples of SQL Server connection strings check here

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

1 Comment

Thank you, that's the answer, I really don't know how couldn't I see something that obvious! Thank you once again for explanation!
2

Alternatively, there is a DataContext constructor that takes a connection string parameter that you could use if it's a temporary change and are planning to switch back to the one that you used to use.

Comments

1

Other way would be copy the connection string and make another one for your local. Open you EDMX properties and in the connectionstrings dropdown select the local connectionstring.

Comments

0

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

In the model.context.cs file there is a constructor:

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

if we create another constructor in that file such as:

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

Then we can pass any connectionstring we want using the new constructor assuming the replaced connstring has the same database structure as the original EF connstring.

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.