ASP.NET SQL Server Sessions and deployment - asp.net

I just deployed my first ASP.NET App to server and everything would be fine if not problems with database... I have sessions stored in SQL Server as two tables. Those tables are operated thru stored procedures. When deploying app I have moved database by making a backup copy of my local db and uploading it to production server. This caused that names were mixed and stored procedures were not working.
Is there a way to deploy database witch changed names ?! Or every time I deploy application to server I need to run asp's create-session-in-db app ?!

It's better to deploy the database using SQL scripts then backup/restore or copy. You can tailor the scripts to your specific need at the time, eg. alter, drop/create. You also get a record of what your data structures are that can be filed with your app.
Simon

Related

Publish ASP.NET project with local data on Azure

I'm quite new to ASP.NET and I encountered a problem when publishing my project to Azure. After configuring the connectionStrings in Web.config, I have successfully uploaded my local database structure to Azure. However, all tables on Azure are now empty, without any local data. So how can I upload both the database structure as well as the data in it? Thanks in advance.
To migrate an existing SQL Server database to Azure SQL Database you can export the schema as a TSQL script and then execute that script against Microsoft Azure SQL Database as follows:
1.Open SQL Server Management Studio and connect to an instance of the Database Engine.
In Object Explorer, right click a database to open a menu, select Tasks…, and then select Generate Scripts.
2.Choose objects to export.
3.Set scripting options. You have the options to save the script to file, clipboard, new query window; or publish it to a web service.
4.Set advanced scripting options.
You can also set the Types of data to script to one of the following based on your requirements: Schema only, Data only, Schema and data.
5.After the script is created, you have the option to modify the script before running the script against an Azure SQL Database to transfer the database.
You can now run this script on your Azure SQL Database.
For more details, you could refer to this article.
You have to create a post deployment script. If the tables are created just fine on your azure application, then you must define what default data they will have. So in your post deployment script you will insert the data you want.

How can I implement a local testing database for my Azure Website?

I have a website I'm developing that uses an SQL Azure database. I want to be able to test my website using a database locally hosted on the debugging machine so that my designer can work on style and content without having to deal with the overhead of firing up the Azure emulator and communicating with an external service as he is often in areas with no-connectivity.
I imagine it would be possible to extract the .sql scripts to create the database and execute them every test run, but this seems tedious. Similarly I'm not sure what the best way to configure these deployment details would be in order to switch between development, and published configurations. I'm a new web-developer cutting my teeth on a rather large project.
Using ASP.NET MVC4 and have MSSQL 2012 installed for what it's worth.
You can export your SQL azure database as .bacpac format and then import it into your sql server database. It will create all tables and fill with data. You don't need to do it on every test run, just do it once and you will have proper database for debug needs.
Switching between debug and release (or you can rename it if you want, e.g. Local and Production) configurations and using different web.config (or config transformations) is a good way to work with different settings.
If you want to store your db scripts (db structure or data) in your VCS - you can use Entity Framework migrations (new fancy way) or separate project of "SQL Server database" type (old school but proven way :) ).
Also EF migrations allows you to easily recreate db (with different name) on each run (for unit testing purposes. And then you can use SQL Express file instance (keep in mind that it's only for local work, your designer wont be able to access sql express instances afaik)

Upload Data from Local Database to Live Database in ASP.Net using SQL 2008

I am working on a web application which have two parts.
1) One is the online web site at online server.
2) The second is running on local machines/computers.
The structure of database is same on both live and on local. Now a user can make changes on the local database and then publish them on to the live server.
How can I update data from local database to online database? Which is the best technique to do this?
Use Any of the Version Controller tool like TFS, It would help in check in your changes

Where to start when uploading a SQL Server database to a web server

Here's another question on my lips.
My website uses a database which was created in SQL Server 2008 R2 Enterprise Edition. Where do I start when I plan to upload the database to the web server? My Website will require this database. Should I send the Scripts which created the database to the Staff of the web server so they can Recreate my database, or should I detach my database and place it in the App Data folder, followed by an update of my Connection strings to reference the detached database?
Another thing I fear is the Database version. Will my Database connection break on the web server because of the "Version of database is 655 and cannot be downgraded to 612" Error? and If yes, How would I prevent that?
The Best way would be to
1: Send them the scripts, let them run it on their side, they should then be able to provide you with server name, database name user id etc.
2: Create a .bak backup file of the database and send that to them and ask them to restore it for you, this way you save a lot of the hassle of creating scripts and you also ensure that the database is like you want it and you know they haven't made a mess of restoring the scripts.
You can also ask them if they don't have some sort of management console where you can upload the database yourself
My suggestion would be to create a back up of the SQL database, and give that to the web server admin to restore on their server. This will mean that you can guarantee that you will get no problems with the structure, and you should simply have to change the connection string in your Web.Config (assuming that you have always created your connections in code based on the connection string in the web.config), to contain a user name and password that your web server admin gives you (if it's a back up and restore of your db, assuming you use SQL authentication, the new db on the web server will have the same users anyway).
Some options;
If you have access via Management Studio just use the import/export tools or the Copy Database Wizard
If the remote sql server can read from one of the site directories you have access to upload a .bak backup and restore, or upload the database files proper and use one of the sp_attach* procedures
Script the database (including data) upload the individual files & create a quick and dirty script that will execute them.

How do I migrate a SQL MDF File to a production SQL Server? (ASP.NET)

I have an ASP.NET project that also uses a SQL MDF File. My target server is SQL 2008R2 or SQL Azure.
I would like to know what deployment options I have as I migrate from DEV to PROD. In case it matters I'm not under any regulation to maintain PII or similarly private data.
How do I move my test schema and perhaps data to production?
You can move the entire database, including the data by attaching the MDF file to the new SQL server. Otherwise you can select all objects and generate CREATE scripts to copy the schema over.
Yes, you can attach to the MDF file directly, or do a backup / restore to get it over to SQL Server 2008.
I haven't played with SQL Azure... From what little I've heard I think you might be stuck scripting the data as durilai suggested (last I heard we're not allowed to do backups / restores for SQL Azure).
In SQL Server Management tools, right click on the database and click 'Script Database As' to create an SQL script for your database. You can also do something similar at the table level if you want the data.

Resources