CONTROL DATABASE issue when migrating SQL database to Azure - sql-server

I'm following this tutorial on Microsoft Docs. I've reached the part where I use the "Data Migration Assistant", but after selecting the target Azure database and clicking "Next", I get the following error:
An unexpected error occurred.
Current principal does not have CONTROL permission on securable AzureDatabaseName of class DATABASE.
I'm using the only user of the Azure SQL server - the server admin, which should have all permissions. I've verified that the user is 'db_owner' by using IS_ROLEMEMBER.
Am I missing something?

I had the same issue. This seems to be a bug in Azure SQL databases. If you have dots in the database name it does not work. I replaced the dots with slashes and it worked for me.
You do not need to recreate the database. A rename worked fine for me:
You have to make sure, that no-one else is using the database!
Connect to master table and execute the following script on the Azure SQL Server:
USE master;
GO
ALTER DATABASE [my.database]
Modify Name = [my-database] ;
GO
Here is a link on how to rename Azure SQL databases:
https://learn.microsoft.com/en-us/sql/relational-databases/databases/rename-a-database

Also make sure to create a firewall rule for your incoming connection. This error can be a bit of a red herring.

I deleted everything - the database, the sql server, and the resource group. Then I recreated everything using the same names, except the database name - which previously contained dots - and this time the migration tool worked. I guess I just encountered some bug.

if you have dots in target database name, you have to remove or replace the dots in db name.
Like: 'demo.customerdb' to 'demo-customerdb'
You can use Sql Management Studio for db renaming:
connect target database server
select target database
press "F2" key or right click on target database then select
"Rename"
remove dots (.) from the database name and that's it! :)
After then, you can try migration process again from the start.

Related

Azure SQL and Visio 2019 Plan 2 Database Reverse engineering wizard Fails

Screenshot of ErrorI am using Visio 2019, trying to reverse engineer a Azure SQL server. I have successfully created multiple User data sources to use in the wizard using both our DB-admin user and my admin azure directory logins. The database credentials are successfully verified and the tables/views i want to reverse engineer are about to load in when i get the following:
Visio reverse engineer database wizard raises error:
"Error! Cannot extract column definition for the table/view . The definition is not
available or you may not have sufficient privileges."
with a text box that says:
"Could not find server "database name"* in sys.servers. Verify that the correct server name was specified. If necessary, execute the stored procedure sp_addlinkedserver to add the server to sys.servers."
I can neither find sys.servers nor run sp.addlinkedserver as it does not exist. though, sys.sysservers does exist.
I starred database name since instead of showing the target DB of "DB_2.0" it shows "DB_2" which is not the full name of the Database.
As i mentioned above i believe that i have sufficient privileges as i have tried both the admin username and password and my admin login using azure directory. So it may have something to do with not having the sys.servers table?
Is there a way to create the sys.servers table or create the stored procedure sp.addlinkedserver as Visio is requesting? Is it advisable to do is Azure SQL, could the naming convention of our DB have anything to do with the error?
Worked with MSFT support, they had me rename my database from DB_2.0 to DB_2. I created a new connection DSN and it worked perfectly afterwards. Apparently visio doesn't like the ".0" in a connection string. It would be nice if i could have eddited the connection string in a text file so I did not have to rename my entire DB.

SSMS 2016 Error Importing Azure SQL v12 bacpac: master keys without password not supported

I have done this dozens of times but just recently ran into this error. Here are the steps I have gone through to get here:
Create a copy of my Azure SQL v12 database on the same server as the original
Export the copy-version (completely inactive from user interaction) to blob storage
Download the .bacpac file from blob storage to my local drive
In SSMS (October 2016 release) my local sql server instance, right click Databases and choose 'Import Data Tier Application'
Choose my recently downloaded bacpac file and start the import
It only takes a few seconds for it to bomb out and I get the error:
Error SQL72014: .Net SqlClient Data Provider: Msg 33161, Level 15, State 1, Line 1 Database master keys without password are not supported in this version of SQL Server
Error SQL72045: Script execution error. The executed script: CREATE MASTER KEY;
I followed the same process for the same database 1.5 months ago any everything worked fine...Is anyone else experiencing this??? I have SSDT version 14.0.61021.0 installed - not sure if that matters or not. I'm also running SQL Server 2016 Developer Edition (v13.0.1722.0).
I had the same problem. After speaking to Azure support they found out the issue was caused because a blank database master key is created to encrypt the storage credentials for the auditing (auditing is an optional setting).
Note that database auditing settings are inherited from the server settings.
Anyway, the work around they came up with was:
Disable auditing on the server (or database)
Drop the database master key with DROP MASTER KEY command.
Then the export works as expected. Hopefully Azure will fix this issue soon so that auditing and export can work together.
Update 21st March 2017 Better work-around From MS
As the fix will take some time to be deployed, they also suggested an
alternative solution, which will not require any additional steps
(like disabling auditing or the steps form the blog) on your side to
avoid this issue. After auditing is enabled, please update the master
key and set the password. Setting a password for the existing master
key will mitigate the issue. Also, setting the password will not
impact auditing and it will keep working. The syntax to add the
password is as follows:
-- execute in the user database
ALTER MASTER KEY ADD ENCRYPTION BY PASSWORD = ‘##############’;
The link also has a PowerShell script you can use to remove the offending SQL Statement from the .bacpac file.
Okay the way I ended up resolving this issue was to do the following:
Create a copy of the SQL Azure database on the same server as the original
In that database run the following script:
ALTER MASTER KEY REGENERATE WITH ENCRYPTION BY PASSWORD = [password here];
Follow steps 2-5 in the original post
I haven't seen documentation on this, but apparently when you create an Azure SQL database it creates a database master key (DMK) without a password, and in SQL Server 2016 this is not okay. Hopefully this helps somebody else out.
Note: I was able to do this since I only wanted the data from the original database to refresh my local development copy - I haven't fully researched the implications of this.
You need to:
remove the master key object from the bacpac
remove the credential object from the bacpac
There is this script published on Microsoft blog, run it, and will do all the above.
C:\PS> .\RemoveMasterKey.ps1 -bacpacPath "C:\BacPacs\Test.bacpac
Fix corrupt bacpac created by removing master key.
The Sugestion to run the script RemoveMasterKey, also created a corrupted bacpac file in my case by inserting  into the model.xml file in multiple places.
There is a way to edit the bacpac by extractig the files, Removing the offending characters in the model.xml file and then generating a new checksum for the Origin.xml file
once done Zipping the files back up with the extension .bacpac allows you to import the backpac.
Fix found at:
http://inworksllc.com/editing-sql-database-azure-bacpac-files/
checksum generator:
https://github.com/gertd/dac/tree/master/drop/debug
Steps provided:
1) Update the zip file with the modified model.xml
2) Rename the zip file with the bacpac extension
3) Run dacchksum.exe /i:database.bacpac (where database.bacpac is the name the bacpac file)
4) Update Origin.xml in the bacpac file with the new value provided by dacchksum.exe

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

Why doesn't VS show my created database in the 'Select or Enter a Database name' dropdown list?

I created a database named sample in SQL server management Studio 2008 and created a table too. But When I wanted to connect to the created database from the Visual Studio 2010, it did not show my created database.
All I did is I clicked ..
Tools --> Connect to Database --> Selected the server name --> Clicked 'Use Windows Authentication'---> clicked the drop down list of 'Select or enter a database name'.
It dint show my created database sample but showed master, model, msdb, Reportserver, reportserverTempdb, Tempdb.
If I enter the database name, I get the following error:
"This connection cannot be tested because the specified database does not exist or is not visible to the specified user"
What could be the problem and how do I solve it? I am looking forward to solve this problem as soon as possible.
Hope you must have resolved this... otherwise I followed the following steps
Goto SQL Server Object explorer
Add the SQL server - your_pcname\SqlExpress
Add the new database
Create tables into it
Then - try to create the connection; it should show the new database created.
For someone who came here just like me, in my sql server, there was a failed restore attempt of the same database. It said XYZDatabase (Restoring...). The issue got resolved when I deleted that failed restore.
Mention the correct server name of the specific database to which you want to connect.
Open SQL Server > Right click on the database which you want to connect > properties> Click View Connection Properties (In the left side written in blue color)> There is the server name, copy that and paste it in the Connection Server Name in Visual Studio Project on which you want the data.
I hope this helps.

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.

Resources