When publish a MVC website via Visual Studio it rewrites the connection string for Entity Frameworks with an invalid one.
It appears to be the same invalid one it created when I first imported the database model (not code first) The correct connection string is in my local web.config, and there are no changes being made by the web.release.config file.
Correct connection string:
<add name="Entities" connectionString="metadata=res://*/Models.MODModels.csdl|res://*/Models.MODModels.ssdl|res://*/Models.MODModels.msl;provider=System.Data.SqlClient;provider connection string="data source=localhost;initial catalog=R4S-MOD;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Generated connection String:
<add name="Entities" connectionString="Data Source=localhost;Initial Catalog=R4S-MOD;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework" providerName="System.Data.EntityClient" />
When you do a release publish they should show you a popup where you choose if you want to do filesystem or iis deployment. there is a section in the wizard which has connection string. check it there, if there is already a preselected value for your connection string – qamar
Related
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="data source=CODE-SERVER\SQLSILENT;initial catalog=pos-standard;persist security info=True;user id=sa;password=abc123**;MultipleActiveResultSets=True;App=EntityFramework"" 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="data source=.;initial catalog=pos-standard;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
I also attach here a error window
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.
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
Sorry if this has been asked, but I've gone through all of the other posts I can find and everyone seems to be using an EDMX, and not a "production" database.
I get the following error:
System.Data.Entity.Core.MetadataException: Unable to load the specified metadata resource
when attempting to access my application. My connection string is as follows:
<add name="FormAssemblyEntities" connectionString="metadata=res://*/Models.Entities.FormAssembly.csdl|res://*/Models.Entities.FormAssembly.ssdl|res://*/Models.Entities.FormAssembly.msl;provider=System.Data.SqlClient;provider connection string="data source=server\instance;initial catalog=dbname;user id=userid;password=password;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
This works perfectly if I am running it locally and it connects to the edmx with the following connection string, but as soon as I put it on our UAT server and point it to the database, I get that error.
<add name="FormAssemblyEntities" connectionString="Data Source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\FormAssembly.mdf;Initial Catalog=FormAssembly;Integrated Security=SSPI;MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" />
I really have no idea where to start. The database appears up to date, the user has access, and the server has access to the SQL server.
I have also tried replacing the res://*/ with res://FormAssembly/ and res://FormAssembly.dll/, but the former results in the same error, and the latter says the dll can't be found (the DLL is in the bin directory).
Any help would be appreciated.
Thanks,
Travis
In my case, the metadata part of my connection string was malformed.
The following connection string worked in my case:
<connectionStrings>
<add name="NorthwindEntities" connectionString="metadata=res://*/Northwind.csdl|res://*/Northwind.ssdl|res://*/Northwind.msl;provider=System.Data.SqlClient;provider connection string="data source=(local);initial catalog=Northwind;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework""
providerName="System.Data.EntityClient" />
</connectionStrings>
This is the connection string and when I change the property of the database file (database1.mdf) to "do not copy", it causes an error.
<connectionStrings>
<add name="ClassLibrary1.Properties.Settings.Database1ConnectionString"
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
That's probably because of AttachDbFilename=|DataDirectory|\Database1.mdf that you can't not copy the database to the DataDirectory.
The connection string tries to find and attach the database from the given address and it can't find it. you can attach the db first and then use this connection strings:
<add provider connection string="data source=.;
initial catalog=Database1;
integrated security=True;/>
This question has probably been asked a thousand times but all the answers that I have seen are not relevant to my question.
I have an asp.net web site setup locally to connect to sql and I used the exact same connection strings in the WPF App.config file
<connectionStrings>
<add name="TrackingConnection" providerName="System.Data.SqlClient" connectionString="Data Source=RAIDSHIPPING\FRTOOLS; Initial Catalog=SHIPPING; User Id=sa; Password=password" />
<add name="RMAConnection" providerName="System.Data.SqlClient" connectionString="Data Source=RAIDSHIPPING\FRTOOLS; Initial Catalog=FRTOOLSRMA; User Id=sa; Password=password" />
<add name="PickListConnection" providerName="System.Data.SqlClient" connectionString="Data Source=RAIDSHIPPING\FRTOOLS; Initial Catalog=Picklist; User Id=sa; Password=password" />
<add name="ShipWorksConnection" providerName="System.Data.SqlClient" connectionString="Data Source=RAIDSHIPPING\FRTOOLS; Initial Catalog=ShipWorks; User Id=sa; Password=password" />
<add name="SupplyConnection" providerName="System.Data.SqlClient" connectionString="Data Source=RAIDSHIPPING\FRTOOLS; Initial Catalog=SupplyManager; User Id=sa; Password=password" />
</connectionStrings>
As usual this works on the local machine but on the network machine I get a "A network-related or instance-specific error occurred while establishing a connection to SQL Server." error.
Like I said this connection string is copied exactly from the asp.net web application, web.config file connection string which the network machine consumes fine. I have the App.config properties set to Copy always also the Sql server configuration is set up to enable Named Pipes and TCP/IP. Windows Firewall has port 1433 open. I thought the Copy always property being set would have solved the problem since the program wouldn't work because images were causing it to break until I set their properties to copy always. I've restarted the SQL Server and machine.
THIS CONNECTION STRING WORKS
On my Local system i was using the database connection string
<connectionStrings>
<add name="GaugeSelectorEntities" connectionString="metadata=res://*/Gage.csdl|res://*/Gage.ssdl|res://*/Gage.msl;provider=System.Data.SqlClient;provider connection string="Data Source=GEORGE1\SQL08R2;Initial Catalog=GaugeSelector;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
This works perfectly fine.
CHANGED TO ATTACH DB FILE INSTEAD AND IT THROWS ERROR
Now i have to deploy the WPF application and so i want to attach the mdf file from the database. So as suggested from existing resources on web i change the string to
<connectionStrings>
<add name="GaugeSelectorEntities" connectionString="metadata=res://*/Gage.csdl|res://*/Gage.ssdl|res://*/Gage.msl;provider=System.Data.SqlClient;provider connection string="Data Source=GEORGE1\SQL08R2;AttachDbFilename=|DataDirectory|\DB\GaugeSelector.mdf;Initial Catalog=GaugeSelector;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
The only change being
AttachDbFilename=|DataDirectory|\DB\GaugeSelector.mdf;
I infact copied the mdf file of database from it's location to a folder DB in the executable path. By the way i was using LINQ to EF. But now i start getting the error.
{"The underlying provider failed on Open."}
Now i read somewehere it might happen if object context is not opened. So i put
GSData.Connection.Open();
But now it breaks here with the same error.
Is my approach itself wrong (Then what should be the approach) or do i just need some minor corrections on the connection string?