1

When i change connection string after publish project in visual studio it is giving me an error

Here is my app.config file

 <connectionStrings>
   <add name="DataContext" connectionString="metadata=res://*   
  /Model.DataContext.csdl|res://*/Model.DataContext.ssdl|res:  
    //*/Model.DataContext.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=CODE-SERVER\SQLSILENT;initial catalog=pos-standard;persist security info=True;user id=sa;password=abc123**;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
 </connectionStrings>

and in new app.config file i want to replace this connection string it my local database connection string.

 <add name="DataContext" connectionString="metadata=res://*/Model.DataContext.csdl|res://*/Model.DataContext.ssdl|res://*/Model.DataContext.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=pos-standard;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

I also attach here a error window enter image description here

Shahbaz
  • 65
  • 1
  • 1
  • 8
  • You need to re-sign the application and deployment manifests after you have edited the config file: https://msdn.microsoft.com/en-us/library/dd465299.aspx http://stackoverflow.com/questions/25004056/resign-clickonce-manifest-using-mage-exe – mm8 Apr 13 '17 at 13:37
  • @mm8 You are right this is a one way through we can solve this problem but here in my situation I couldn't resign/publish the application – Shahbaz Apr 13 '17 at 13:41
  • 1
    If you can't resign it, you have two options: 1. Don't use ClickOnce. 2. Don't change the config file. – mm8 Apr 13 '17 at 13:52
  • If you use Windows Authentication you won't have to change the connection string, unless you want to connect to a different server. You can store server, database names as *user* settings and build the final connection string at runtime. Storing a username/password in the connection string is a **bad** idea, as the end user can easily read them. – Panagiotis Kanavos Apr 13 '17 at 14:02
  • @mm8 I think your answer is suitable for me.thanks – Shahbaz Apr 13 '17 at 14:04
  • @PanagiotisKanavos yes you are right it is a bad idea,I will try to avoid this.thanks – Shahbaz Apr 13 '17 at 14:09

2 Answers2

1

Are you sure that your database authorises Integrated security ? Can you connect using SQL server management studio with integrated security ?

If yes, try to not replace all the connection string but only remove username and password ant put integrated security = true, and change server name.

Finally, check the database server name may be .\Something.

Coskun Ozogul
  • 2,389
  • 1
  • 20
  • 32
0

You need to re-sign the application and deployment manifests after you have edited the config file. Please refer to the following links for more information about this.

http://msdn.microsoft.com/en-us/library/dd465299.aspx

Resign Clickonce manifest using mage.exe

Community
  • 1
  • 1
mm8
  • 163,881
  • 10
  • 57
  • 88