Error deploying database to SQL Azure - sql-server

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

Related

Automating import of data-tier application (SQL database) from Azure with a Master Key

When I extract a data-tier application from a Microsoft Azure SQL database that has a Master Key, I was unable to import it into SQL server on my local PC.
You will find others had this issue here: SSMS 2016 Error Importing Azure SQL v12 bacpac: master keys without password not supported
However the steps provided as the answer did not work on my installation.
Steps are
1. Disable auditing on the server (or database)
2. Drop the database master key with DROP MASTER KEY command.
Microsoft Tech Support verified this solution did not work on my installation of SQL Server and after actually taking remote control of my PC and trouble shooting, they were unable to determine why this was occurring.
I needed to find a way to remove the Master Key from the bacpac file. I have a Powershell script to remove the Master Key from the BACPAC file but it requires extracting, renaming files and running scripts from Windows Powershell to get the db imported.
Does anyone have a program or set of scripts which would automate the process of removing the Master Key and importing a SQL DB from Azure with a single command?
I am new to this forum. Please do not be harsh with this post. I am trying to do the best I can to help others to save the many hours I spent coming up with this.
I have cobbled together a T-SQL script which calls a Windows Powershell script (also cobbled from multiple sources) to extract a data-tier application (database) from Microsoft Azure SQL database and import it into a database on my local SQL Server by running ONE command. Over the months I found some of the code that is in my scripts from other blogs etc. I am not able to provide the credit due to those folks as I didn't keep track of where I got the info. If you are reading this and you see your code, please take credit. I apologize for not being able to give you the credit for your work.
There may be configuration settings on your PC and your local SQL server that need adjustments as this entire solution requires pretty much full access to your computer. If you run into trouble with compatibility, let me know and I will do the best I can to let you know how my system is configured in case it will help you.
I am using Windows 10 Pro and Microsoft SQL Server Developer (64-bit) v12.0.5207.0
I have placed the two files that do all the work on GitHub here: https://github.com/Wingloader/Auto-Azure-BACPAC-Download.git
GetNewBacpac-forGitHub.sql
GetAzureDB-forGitHub.ps1
WARNING: The Powershell script file will store your SQL sa password and your Azure SQL login in clear text!
If you don't want to do this, don't use this solution.
My computer is owned and controlled solely by me so I am able to open up the security in my system and I am willing to assume the responsibility of safeguarding it.
The basic steps of my solution are are accomplished as follows: (steps 1 and 2 are optional as I like to keep a version of the DB I am working with as of the point in time I pull down a clean production copy of my Azure DB)
Back up the current DB as MyLocalDB.bak.
Restore that backup from step 1 to a new DB with the previous day stamped at the end of the DB name (e.g., MyLocalDB20171231)
Delete the original MyLocalDB database (needed so we can recreate the DB with the original name later on)
Pull down the production database from Azure and create a new database with the name MyLocalDB.
The original DB is deleted in step 3 so that the restored DB can use the original name (important when you have data connections referring to that DB name)
In Step 4, the work of extracting the data-tier application DB from Azure is initiated by this line in the T-SQL:
EXEC MASTER..xp_cmdshell '%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -File C:\Git\GetUpdatedAzureDB\GetAzureDB.ps1"'
The Powershell script does the following:
The target for the extract is a file named today.bacpac (hardcoded). The first thing to do is delete that file if it already exists.
Extract the DB from Azure into the today.bacpac file.
Note: my DB on Azure has a Master Key for encryption. This will need to be removed from the files prior to importing the bacpac file into your local DB or it will fail (this may not be required in SQL 2017 according to my previous conversations with MS Support). If you do not use a Master Key, you can either strip out the code that does this step or just leave it alone. It won't remove anything if it isn't there. It would just add a little overhead to the program.
Open the today.bacpac file (zip file) and remove the MasterKey node from the Origin.xml file.
Modify the Model.xml file to updates the SHA hash length. This is required in order for the file not to appear to have been tampered with when SQL opens the bacpac file.
Re-zips the files back into a new file today-patched.bacpac
Runs this line of code (from Powershell) to import the bacpac file into SQL Server
&C:\Program Files (x86)\Microsoft SQL Server\140\DAC\bin\SqlPackage.exe" /Action:Import /SourceFile:"C:\Git\GetUpdatedAzureDB\today-patched.bacpac" /TargetConnectionString:"Data Source=MyLocalSQLServer;User ID=sa; Password=MySAPassword; Initial Catalog=MyLocalDB; Integrated Security=false;"
After editing the two files to provide updated paths, usernames and passwords, run the SQL script. You do not need to edit the scripts again. You can run the SQL script again without modification and it will create a new copy of your Azure DB.
Done!

Migration of SQL server database to Azure

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.

Automated Azure SQL DB export fails - indexing for document type .xml is not supported on MS Azure SQL DB v12

I'm using Azure SQL DB automated export feature. Everything worked like a charm, but recently it started failing:
Automated SQL Export failed for XXX:XXX at 8/2/2015 4:11:22 AM. The temporary database copy was made, but this copy could not be exported to the .bacpac file.
I've checked "Import/Export History" of my Azure SQL Server and saw following error details:
Error encountered during the service operation. Indexing for document type .xml is not supported on Microsoft Azure SQL Database v12.
I have no idea what it is. Probably it's something linked with FTS feature that I'm using, but I've done nothing to my database since my last successful automated exports, so I guess this must be some Azure issue.
Do you know how to fix this?
Do you know if it affects backups made by default by Azure SQL DB service?
If you have full-text index on a table in the database you may see this. Quick solution is to drop the index and recreate after import into Azure DB. Azure DB taken backups are not impacted by this and you can do PITR if needed.
1. Open a CMD Window
2. Run the following command to export using SqlPackage.exe:
“C:\Program Files (x86)\Microsoft SQL Server\120\DAC\bin\SqlPackage.exe” /a:export /ssn:(localdb)\ProjectsV12 /sdn:myDB /tf:my.bacpac /p:VerifyFullTextDocumentTypesSupported=false
The VerifyFullTextDocumentTypesSupported flag is set to false, which allows export
to continue without any verification. The reason this is not allowed by default
is to avoid unexpected behavior upon migration to Azure Sql Database.
Disclosure: I work on the SQL Server team responsible for Import/Export. A fix for this issue during automated export will be added in the future, but an immediate workaround is to use SqlPackage.exe to export locally. The solution is to set the VerifyFullTextDocumentTypesSupported flag to be false as mentioned in Satya's answer.
Exact steps to use SqlPackage.exe:
Install the latest July DacFramework.msi release, or ideally install the latest SSMS Preview which has support for the most recent Azure SQL DB features. Support for Full Text Search and this config option was added this year, hence the need to update SqlPackage.exe. The version you were using to Export was out of date and hence did not know about Full Text Search support.
Run the following command to export using SqlPackage.exe.
For version 120 (this is the July RTM update):
“C:\Program Files (x86)\Microsoft SQL Server\120\DAC\bin\SqlPackage.exe” /a:export /ssn:(localdb)\ProjectsV12 /sdn:myDB /tf:my.bacpac /p:VerifyFullTextDocumentTypesSupported=false
For version 130 (Installed by SSMS Preview release):
“C:\Program Files (x86)\Microsoft SQL Server\130\DAC\bin\SqlPackage.exe” /a:export /ssn:(localdb)\ProjectsV12 /sdn:myDB /tf:my.bacpac /p:VerifyFullTextDocumentTypesSupported=false
Finally, to answer your question #2 this will not affect backups or Point in Time Restore (PITR). It is a configuration issue with the Import/Export service and the issue is localized to this feature.

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.

SQL Server Copy Database Issue

I'm running the copy database wizard on a 2008 R2 instance of SQL Server.
The database I want to copy is a SQL 2000 database.
I'm copy that database to another SQL SErver 2008 R2.
The wizard uses SQL authentication for both servers, and both are sysadmins.
When I run it, I get the following error (FYI I have tried both copying the logins and leaving them out):
Event Name: OnError
Message: ERROR : errorCode=-1073548784 description=Executing the query "sys.sp_addrolemember #rolename = N'RandomRoleName..." failed with the following error: "The role 'RandomRoleName' does not exist in the current database.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
helpFile= helpContext=0 idofInterfaceWithError={C81DFC5A-3B22-4DA3-BD3B-10BF861A7F9C}
StackTrace: at Microsoft.SqlServer.Management.Dts.DtsTransferProvider.ExecuteTransfer()
at Microsoft.SqlServer.Management.Smo.Transfer.TransferData()
at Microsoft.SqlServer.Dts.Tasks.TransferObjectsTask.TransferObjectsTask.TransferDatabasesUsingSMOTransfer()
Any help would be appreciated!
Jim
My suggestion is dont use the copy database wizard. Create a full backup of the database on the 2000 server and then restore it on the 2008 server.
If you google "Microsoft.SqlServer.Management.Dts.DtsTransferProvider.ExecuteTransfer Copy Database Wizard" you will find that many many people have gotten this same error or other nearly identical smo errors... no-one appears to have gotten past it.
That's isn't to say its impossible... just, restoring a backup is so much easier then the wizard or troubleshooting the wizard. Good luck.
The copy wizard had missed some security and IIRC it's caused by subtle differences in security tables, principals etc between the 2 versions.
Frankly, the easiest way is to do one of these two:
backup/restore
detach, copy, attach
If you don't have access to the O/S and can't get it, another option is to create the missing role(s) in the background as the copy runs. You have to catch it between the creation of the files and when it tries to reference the roles, but there are a few seconds in which to create them if you keep clicking execute - I managed to create 9 roles.
Unfortunately, you'll end up with the roles in another database too (while yours cannot be used) so those need to be deleted.
Of course, this is only an option when you really can't use the other method.
Though the answer which is using the backup technique solves the problem generally, after facing the same issue several times, I was able to trace down the root of the problem using the Event Viewer of Windows to that the Database Copy wizard, using the SQL Agent, will eventually create a Job for the agent to run, after which the Agent will run using its own credentials (i.e. the credentials that you can look up in Windows Services, in my case, NT Service\SQLAgent$SQL2014)
All you need to do is to go the folder where SQL Server creates DB files (e.g. C:\Program Files\Microsoft SQL Server\MSSQL12.SQL2014\MSSQL\DATA by default for SQL 2014) and give the SQL Agent windows user write/read access on the folder.
The reason can be that a file with the new Database name already exist on the filesystem. We encountered this when we renamed Database X to X_Old, and tried to copy database Y to X. This cannot be done, because database X_Old is still associated with the filename X.
Either delete the conflicting database, or rename the file on the file system.
See http://codecopy.wordpress.com/2012/01/03/error-while-copying-a-database/

Resources