So we have developed an MVC application with EF database first and are trying to deploy the solution to Production environment. however the database server is on a different server and hence we would have to provide a conenction string pointing to the DB server. We tried couple of methods but weren't successful.
Whats the approach for deployments for EF DB first?
Have you tried this code?
Configuration connectionConfiguration = WebConfigurationManager.OpenWebConfiguration("~");
connectionConfiguration.ConnectionStrings.ConnectionStrings["test"].ConnectionString = txtConnectionString.Text;
connectionConfiguration.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("connectionStrings");
It will rewrite your web.config with new values
When deploying to a production environment, an application is typically compiled in Release mode. In this mode you can use Web.Release.config to specify the variables that should be different in production.
Say your connection string in Web.config is
<add name="MyContext"
connectionString="DevConnectionString"
providerName="System.Data.SqlClient" />
You can add this in Web.Release.config:
<add name="MyContext"
connectionString="ProdConnectionString"
providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes"
xdt:Locator="Match(name)" />
When deploying to production the connection string will automatically change to "ProdConnectionString".
For more information on Web.config transforms see How to: Transform Web.config When Deploying a Web Application Project
Related
I want to deploy my WPF project but at the client machine it throws an exception that connection is not able to open.
I use a hardcoded string I don't know how to set dynamic connection string which changes at every computer. Someone please guide me with deployment of a WPF project with local SQL Server database or how to set connection string dynamically.
What I have done:
Deploy and export database with .EXE
Deploy without database and with SQL script so on the client machine it creates database before starting setup
This is the connection string which I am using:
<add name="connect"
connectionString="Data Source=(LocalDB)\FoodManagmentUpdate;AttachDbFilename=C:\Program Files (x86)\SolBuz\Shreeji Snacks\FoodManagmentUpdate.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
I already tried with :
<add name="connect"
connectionString="Data Source=(LocalDB)\FoodManagmentUpdate;AttachDbFilename=|Data Dictionary|FoodManagmentUpdate.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
I installed SqlLocalDb on my client's machine, but still it won't work. And FoodManagmentUpdate is the object of SqlLocalDb which I also created on the client computer.
I Changed my AttachDbFileName=|DataDirectory|\Databasename.mdf and now it works but i have to copy whole folder 'bin' which resides in your solution folder and that bin folder must contain your database in it. This way i get my solution.
I recently upgraded my PC from Windows 7 to Windows 8.1 and am now having problems resetting up my local DNN5 environment.
I pulled my DNN5 instance down from a remote git repo, and just finished importing all of the tables/data/stored procedures from the production DB to a local instance.
I have updated the connection strings in the web.config to reflect my new database, but still, no matter what I do, I am getting redirected to http://localhost/DNN5/Install/UnderConstruction.htm.
What am I missing?
for completeness, here are my connection strings and a screencap of my db:
<connectionStrings>
<add name="SiteSqlServer" connectionString="Data Source=KMCNUTT-7\DWYATTMSSQL;Initial Catalog=DNN5;User ID=sa;Password=******"
providerName="System.Data.SqlClient" />
<add name="DNN5ConnectionString" connectionString="Data Source=KMCNUTT-7\DWYATTMSSQL;Initial Catalog=DNN5;User ID=sa;Password=******"
providerName="System.Data.SqlClient" />
</connectionStrings>
This almost always happens when you are unable to connect to the database from DNN.
Navigate to
http://localhost/DNN5/Install/install.aspx
and see if it throws a connection error just to be sure.
Is this a local database? If so try using (local)\InstanceName (I assume your instance name is DWYATTMSSQL) so (local)\DWYATTMSSQL
Also make sure that you have SQL authentication enabled in SQL server, instead of Windows Authentication only, which is the default for SQL installations.
The article here
:: http://www.microsoft.com/web/post/how-to-publish-a-web-application-using-webmatrix
states that to publish via FTP I must "enter the connection string for the destination database" and gives examples. It is not clear to me if I have to replace the current web.config string, or if I'm adding one. I also don't understand if I have to mark one as a destination database.
Here is what I have thus far. When I visit website it says "under construction". It would be helpful to know how to get it out of that state, and also turn log error on.
<!-- this is the local connection -->
<add name="SiteSqlServer" connectionString="Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|Database.mdf;" providerName="System.Data.SqlClient" />
<!-- this is the destination db -->
<add name="myConnectionStrings" connectionString="Server=205.xxx.xxx.xxx;Database=mydbname;uid=mydbusername;pwd=mydbpasswd;" providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<!-- Connection String for SQL Server 2005/2008 Express - kept for backwards compatability - legacy modules -->
<add key="SiteSqlServer" value="Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|Database.mdf;" />
.
.
.
</appSettings>
I work on WebMatrix and found your post so I thought I'd provide some answers:
I'm guessing the reason you see "Under Construction" is some applications include some post-site creation configuration as part of their install. For DotNetNuke specifically it looks like you'll want to visit:
http://localhost:port/Install/InstallWizard.aspx
but you can always click the "Run" button from the ribbon after installing any app to start the configuration process if required.
As for setuping but your site publishing you shouldn't ever need to edit the web.config file. In Bakery application shown in the tutorial uses a file-based database so we're able to easily deploy the database through both Web Deploy and FTP using a simple file copy. DotNetNuke on the otherhand uses a full SQL database so we're not able to publish or download the database via FTP. There is no need to enter any additional connection strings to your app locally but you will be responsible for changing the database connection string in the web.config on the server once FTP publishing is done (as well as other settings that may have changed like the site url).
Since Web Deploy is more than just a file copying protocol if you choose Web Deploy as your publishing method we're able to actually sync your local and remote databases. You'll need to enter the connection string for the remote database server on the Publish Settings dialog along with your other connection information and you can use the Validate button to test those settings.
To view your error log you can go to the Site workspace in WebMatrix and then click on Requests in the left-hand navigation. Make sure the Capture Requests toggle in the ribbon is turned on. Additional options to tweak what is logged are also available in the ribbon.
Hope that helps,
Andrew
I'm running Visual Web Developer 2010 Express. I have added an additional SQLExpress DB to the standard ASPNETDB.mdf. Both are connected through the web.config. Everything runs fine. The connection strings are as follows:
<add name="TrempimModel"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|TrempimModel.mdf;
database=TrempimModel;User Instance=true"
providerName="System.Data.SqlClient" />
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;
User Instance=true"
providerName="System.Data.SqlClient" />
But how do I view the data in both DB files? To my surprise, although the files are refferenced in web.config, the DB Explorer in the IDE does not show them. If I go and add either or both in the DB explorer, strange stuff starts happening - mainly the application is not able to connect to my added DB at application launch.
So what is the best way to view SQL Express table data? Is it through the IDE, or a seperate application? And why isn't the DB explorer showing a connection established in web.config?
Thanks,
Gil
Problem Solved - surprisingly enough, by eliminating the connection sting altogether. That way, the database is created by the DB engine and attached automatically by Management Studio, so the data can be viewed over there, while debugging.
I wander why all the walk-through descriptions eliminate this option which is as hassle free as they come... One point to remember is that you need to exit the Management Studio before running the application with data model changes that will cause the DB to be re-created.
So I'm moving my Asp.net mvc web app over to Arvixe shared hosting. This is the first time I've deployed an MVC app. I have been using SQL Server 2008 Express for the development database. Arvixe provides SQL Server 2008 or MySQL hosted databases.
A couple questions:
1.Can I use the mdf files from my Express database with the new Non-Express prodcution DB?
2.I'm having issues with my connection string. I changed the original web config connection string from this:
<add name="Database1ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
to this:
<add name="Database1ConnectionString" connectionString="Data Source=.;Integrated Security=SSPI;Initial Catalog=ProdsDB"
providerName="System.Data.SqlClient" />
Now I'm getting this error:
Cannot open database "ProdsDB" requested by the login. The login failed
I have setup the database called "ProdsDB" through the Arvixe control panel and added one user. Do I need to add the credentials somewhere in the connection string?
Yes. You're going to need to add User Id=myUsername;Password=myPassword; to the connection string, and you'll need to remove Integrated Security=SSPI
Of course, you'll need to set them to the username and password you created. Also, sometimes hosting providers host the database on a separate server. If that's the case, you'll have to specify the servername in place of the dot.