Migration of SQL server database to Azure - sql-server

I'm trying to migrate one of my database in my local environment to Azure from SQL server management studio, but i'm facing with the following exception.
Please let me know how to resolve this issue. Thanks
Steps I have followed:
From SQL Server Management Studio, Database -> Tasks --> Deploy database to Windows Azure SQL Database
I'm able to connect to the Azure SQL instance
During the process i'm getting the following error, as in the snapshot.
PFB the snapshot of my local and azure SQL server instances,

Right click on the DB you are trying to copy, select "Generate scripts..." to open the "generate and Publish Scripts" wizard.
Click Next or "Choose Objects" from the navigation pane to the left. On the "Choose Objects" step you may want to select the specific tables/sprocs you want to copy, or you can just choose "Script entire database"
On the next page, I recommend selecting the "Save to a New Query Window" option. Then click "Advanced" in the top right corner and scroll to the bottom of the "General" section. The last item in this section is "Type of data to script". You will probably want to change this to "Schema and data" if you want to include the data in your script.
Click Next until it starts to generate the script. When the script is done, it will open a new query window with CREATE / INSERT statements and when you Execute, it will create a copy of your DB. HOWEVER, you will need to update the USE [MyDatabase] statement and you will need to change the "Available Databases" dropdown to the desired Database (i'm talking about the dropdown box above the Object Explorer)

You can use the following methods:
-dacpac
-In Visual Studio -> Tools - SQL Server - SQL Schema comparison & data comparison
Check in the settings windows - use incompatible platforms

You received that error because the version of SSMS you're using is old. Installing the latest version of SSMS will get things working better.

Related

Error deploying database to SQL Azure

I'm using forms authentication to handle users and attempting to deploy my database to SQL Azure, but getting this error message:
The only table of the four listed that I utilize is aspnet_Membership, and the only other table I use is aspnet_Users from implementing forms authentication. What is TextInRowSize and why does SQL Azure care about it? Do I have any option to modify aspnet_Membership to make it compatible?
If it would be easier to remove the current system altogether and replace it with my own, I'm fine with that too.
That looks like an error in the data-tier application framework. I can suggest a workaround to get your database to Azure:
Use SqlPackage.exe (https://msdn.microsoft.com/en-us/library/hh550080(v=vs.103).aspx) from the command line to extract a dacpac file with all table data. Then use SqlPackage.exe to deploy that dacpac file to your database in Azure. The extract command would look something like:
C:\>"c:\Program Files\Microsoft SQL Server\120\DAC\bin\SqlPackage.exe" /a:extract /scs:"Data Source=yourSqlServer;Integrated Security=true;Initial Catalog=yourDatabase" /tf:C:\temp\mydatabase.dacpac /p:ExtractAllTableData=true
And the import command would look something like:
C:\>"c:\Program Files\Microsoft SQL Server\120\DAC\bin\SqlPackage.exe" /a:publish /tcs:"Data Source=yourAzureSQLServer.database.windows.net;User Id=yourUserId;Password=yourPassword;Initial Catalog=yourDatabase" /sf:C:\temp\mydatabase.dacpac
So quick suggestions since I see you are using V12 which should support those properties now.
First make sure you are using SSMS 2014 SP1 at least, this has a number of fixes for using V12. Secondly make sure you install the May 2015 update to DacFX (which is the program that creates bacpac files) you can install it here: http://www.microsoft.com/en-us/download/details.aspx?id=46898
This should get you to the best possible chance of your import/export working.
This was solved by generating a SQL Azure script for the DB, and running it on Azure. Here's how I solved it:
First, open SQL Server, right click the database you want to transfer and click "Tasks > Generate Scripts..."
Next, click "Advanced" on the scripting options panel and find the row "Script for the database engine type." Select "Windows Azure SQL Database" and click OK (Note: if you have data that you want to transfer as well, choose "Schema and Data" from the "Types of data to script" option).
Proceed thru the rest of the script generation dialog, remembering where you saved the script file. Connect to your database server using SQL Server or windowsazure.com. Generate a new query for your new database, enter the script that was generated by SQL Server and execute.
Seems like TextInRowSize stores large data for older SQL Server types such as text and ntext. You would need to change it's type to nvarchar(max).
Here's a link to a more detailed explanation.
http://www.dnnsoftware.com/wiki/unsupported-property-textinrowsize-set-and-is-not-supported-when-used-as-part-of-a-data-package

Can't gain access to my database created though Visual Studio?

I have created a database emailDatabase, its stored in
C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA
In Visual Studio, I use the Server Explorer, click the add new connection button.
The add connection dialog box appears.
Under server name I use the dropdown box and select DEV-5\SQLEXPRESS. I use Windows authentication.
In the Connect to section at the bottom, the dropdown displays: Master, Model, msdb and tempdb and does not display my emailDatabase.
So I select Attach Database File and click browse and follow
local C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA
and select my email database.
The following error occurs :
emailDatabase
You don not have permission to open this file.
Contact file owner or an administrator to obtain permission.
I think my problem is i saved my database wrong, I need to make a back up or something like that. if that's the case please tel me how to make a backup and so on. I really need to move forward from this problem.
When I created my database I right-clicked on databases in SQL Server Management Studio and said new database, then I added columns with a query. then file save all.
How can I get a copy of my database file with all the permissions I need to use it in visual Studio??
When you create a database on the server (using SQL Server Management Studio), you don't have to (and should not!) fiddle around with the database file(s) anymore - let the server handle that for you.
Instead: do a Add Connection in Visual Studio and then specify the server instance (DEV-5\SQLEXPRESS) and the database name (emailDatabase) in your connection dialog.
With this, you're connecting and using a SQL Server database the way it's intended to be used - on the SQL Server instance itself. This is much easier, and much less hassle, than having to struggle with "free-floating" .mdf files and attaching them to your solutions and stuff like that....
So here - fill in DEV-5\SQLEXPRESS into your "Server name" dropdown, and then use the "Select or enter database name" option and enter your database name (or pick it from the dropdown) - it should be there!
DO NOT use the "Attach a database file" option - this is the free-floating .mdf "feature" which is rather clumsy and hard to use and error-prone - again: I recommend not using that...
Had the same problem and I realised the problem was not in VS2010 but my SQLserver.My instance name is OMAFANO ,and that's what my MSSQL connected to under Server Name. Now here's the catch,click on that and connect to OMAFANO\SQLEXPRESS and create all your databases and tables there if you want them to show up in VS2010 the way u stated up there. So under server name in VS2010 also write INSTANCENAME\SQLEXPRESS if you want to see your newly created databases etc. Take a look at the picture:
I thought I had it figured out but problems continue to pop up. So ...
IGNORE EVERYTHING BELOW THIS LINE.
After hours of tinkering I finally figured out how to use SSMS to connect to a SQLServer 2008 database that was created in VS2010, and it is relatively simple. But from the number of unanswered questions all over the place not well documented. Here's how to do it:
In VS right click the project in SolutionExplorer and select Add new item then select Data then SQLServer database. It will prompt you to save it in the app_data folder and create the folder for you if it doesn't exist.
Find the Ssms.exe file (on my system it's in C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE
Right click Ssms.exe and select Run as administrator.
After SSMS opens you can attach the project MDF. It will now be on your list of databases. The database name is a GUID.
You can even run aspnet_regsql against the database to add the Membership tables and sprocs.
IMPORTANT! You can manage this database with EITHER SMSS OR VS but not both at the same time. If you mess with the database from within VS using ServerExplorer you will break the SSMS connection. To fix that you will need to detach and reattach the database.
Run Your Visual studio As Administrator
Go to Visual Studio instance i.e C#,C++ etc
Right click > Run as Administrator
Then now It may work
To connect to a ssms2014 database from visual studio 2013, in the new connection wizard I had to change 'data source' from 'ms sql server database file' to '.net framework data provider for sql server..'. Then I was able to enter [computer name][username] for windows authentication.
I had the same issue, you just type your local server name "sara-PC" instead of
"sara-PC\SQLEXPRESS"
Now you can access your database easily, you can see it in your dropdownlist.
And also please dont use file access method to attatch database, thats not good way.
Also you can put ~....\Data and ~...\log file wherever you want by setting default location using server->rightclick->properties->Database settings.
Definitely this solves your issue.

Best (easiest) way to make a SQL Server dump and import that dump in another SQL Server

I would like to achieve a database export (dump) in SQL Server from one server and import that dump in another SQL Server and not necessarily in the same schema name.
For example if I have a database prepared with all the data set for implement a new DB for a new customer, that db is for example named DB_EMPTY
And then I have to setup the same DB on some external server for a customer for example in the schema DB_MY_CUSTOMER
What is the best/simplest way to export (dump) a DB_EMPTY, and import it in DB_MY_CUSTOMER?
Possibly with SQL Server Management Studio?
An easy way would be to use SQL Server Management Studio, in the Object Explorer right click on the database you want to export, select Tasks -> Back Up, then select a destination and file name in the Destination box at the bottom of the dialog. You can play around with the various settings, but you don't need to.
To restore it on another server is basically the opposite, choose Tasks -> Restore -> Database, in the dialog select From Device, then click the browse ellipsis, from there you get a browse dialog, click Add and then navigate to the back up file you created. You can change the databse name in the To database textbox, and control where the files get stored by going to the Options tab and altering the Restore As column entries in the table labelled as Restore the database files as:.
Just in case someone is ending here and noticing "Tasks -> Back up" option does not exists; on recent versions of SSMS ( v18 for example ), you'll need to use "Generate scripts" option and then on "Advanced" select "Schema and Data" on "Types of data to script".
Credits to: http://statmap.co.uk/?page_id=9207
This is called replication : http://databases.about.com/od/sqlserver/ht/distribution.htm
Try to look to the snapshot replication. It is configurable to determine the destination database.

In SQL Server 2008 R2 script data missing on Script Wizard

In my SQL Server 2008 R2
Script Option Screen of Script Wizard under section Table/View Options Look I find Script Data row and want to turn the option to True but I fail.
I don't find any script data option. Why script data option missing on my SQL Server 2008 R2? Is there any command to generate the insert data option.
Why this problem arise? how to solve it? Thanks in advance
It looks like they removed it from that location. You can still do it by:
Right clicking on the DB
Click on tasks
Click on generate scripts
Go through the wizard and select your tables
On the options page click the Advanced button
Change the "Types of data to script" option, from the default "Schema only" to "Schema and data".
In SQL Server 2008 R2 you can go on the DB, right click on DB -> Tasks -> Generate scripts. This is the wizard for scripting the objects (with or without data). Follow the stepts described on the first page. At the third stept, "Set Scripting Options", after you choose your way to save /publish your data, you go on "Advanced" and there, for General Options, at line "Types of data to script" you can choose to script also your data ("Schema and data").

Is there some way for me to generate SQL Scripts from an already existing database?

Say I already created my database but forgot to save the sql commands do create it.
How could I reverse engineer the code from an already existing database?
I'm using Microsoft SQL Server Express 2008.
You can do this pretty easily by using SQL Server Management Studio (SSMS) - it's available for free if you don't already have it installed.
Connect to the database
Expand out Databases > YourDataBaseName.
Right-click on the database and select the option "Script database as" then "Create To" then finally "File".
That will create the necessary scripts to recreate your database.
To script out all the tables in your database:
Right-click on the database node
Select "Tasks" then "Generate Scripts".
When the wizard appears, click Next.
Select the database. At this point you can check the "Script all objects in the selected database" which does exactly what it says, or if you leave it unchecked you will get the option later in the process to pick which items are scripted.
Click next. Now you're given some scripting options.
I'd suggest scrolling down the list and checking the option to Script Indexes/Script Triggers. You can also script the data if necessary (though I wouldn't do this if you've got a lot of data in your database).
Modify any options you'd like and click Next.
Select the database types you'd like to script (Users/Tables/Views). Click Next.
Now you've got the opportunity to select more specific items. Hit Next and repeat the process of any of your other database types.
Hit next one more time, then select where you'd like the script written to. You get the chance to review your selections.
Click Finish.
Here's a link for the 2008 version SSMS Express 2008
Your RDBMS comes with some sort of "dump" tool that will give you the structure and content of your database, in the form of SQL statements.
As others have mentioned, if you have SQL Management Studio (you should, it's free as part of SQL Server Express). Fire it up, connect to your instance then expand the Database tree.
Right click on your database and select Tasks->Generate Scripts..
Click next, then Next again (which selects all objects in the database by default), pick an output option (defaults as "Save to File"), click next and voila!
If you also want to script the data as well as the schema, in the "Set Scripting Options" window, click on the Advanced button, scroll down to "Types of data to script" (just above the Table/View Options header) and select "schema and data".
[Edit] Tested - The Generate Scripts option exists and works in the (free) 2008 R2 edition of SSMS. See the link in my comment below for the URI for the R2 version.

Resources