ELASTIC_POOL not recognised by Visual Studio Database Project - sql-server

I am creating a Database project for a SQL Database in Azure.
The Target Platform is Microsoft Azure SQL Database V12 which I have set in the project settings.
I then have a post deployment script containing the following code to add the database to an elastic pool
ALTER DATABASE [$(DatabaseName)] MODIFY ( SERVICE_OBJECTIVE = ELASTIC_POOL ( name = mypoolname ) )
Ref: https://learn.microsoft.com/en-us/sql/t-sql/statements/alter-database-azure-sql-database?view=azuresqldb-current#b-moving-a-database-to-a-different-elastic-pool
Because my Post Deployment script is set to build (because it has to as part of being a post deployment script) I get the following error:
Error: SQL72007: The syntax check failed 'Incorrect syntax near
ELASTIC_POOL.' in the batch near:
But I know the syntax is ok, it is obviously not recognising the Azure TSQL.
Is it possible to do this as part of my Visual Studio Database Project?

I'm not sure how you're actually sending the query over to the database server, but in order to bypass a preliminary clientside syntax check you could simply use
exec sp_executesql N'ALTER DATABASE [$(DatabaseName)] MODIFY ( SERVICE_OBJECTIVE = ELASTIC_POOL ( name = mypoolname ) )'

Related

Could not import package. Warning SQL72012: The object exists in the target

I exported my Azure database using Tasks > Export Data-tier Application in to a .bacpac file. Recently when I tried to import it into my local database server (Tasks > Import Data-tier Application), I encountered this error:
Could not import package.
Warning SQL72012: The object [MyDatabase_Data] exists in the target, but it will not be dropped even though you selected the 'Generate drop statements for objects that are in the target database but that are not in the source' check box.
Warning SQL72012: The object [MyDatabase_Log] exists in the target, but it will not be dropped even though you selected the 'Generate drop statements for objects that are in the target database but that are not in the source' check box.
Error SQL72014: .Net SqlClient Data Provider: Msg 12824, Level 16, State 1, Line 5 The sp_configure value 'contained database authentication' must be set to 1 in order to alter a contained database. You may need to use RECONFIGURE to set the value_in_use.
Error SQL72045: Script execution error. The executed script:
IF EXISTS (SELECT 1
FROM [master].[dbo].[sysdatabases]
WHERE [name] = N'$(DatabaseName)')
BEGIN
ALTER DATABASE [$(DatabaseName)]
SET CONTAINMENT = PARTIAL
WITH ROLLBACK IMMEDIATE;
END
Error SQL72014: .Net SqlClient Data Provider: Msg 5069, Level 16, State 1, Line 5 ALTER DATABASE statement failed.
Error SQL72045: Script execution error. The executed script:
IF EXISTS (SELECT 1
FROM [master].[dbo].[sysdatabases]
WHERE [name] = N'$(DatabaseName)')
BEGIN
ALTER DATABASE [$(DatabaseName)]
SET CONTAINMENT = PARTIAL
WITH ROLLBACK IMMEDIATE;
END
(Microsoft.SqlServer.Dac)
I followed the advice on other posts and tried to run this on SQL Azure database:
sp_configure 'contained database authentication', 1;
GO
RECONFIGURE;
GO
However, it says
Could not find stored procedure 'sp_configure'.
I understand the equivalent statement in Azure is:
https://learn.microsoft.com/en-us/sql/t-sql/statements/alter-database-scoped-configuration-transact-sql?view=sql-server-2017
What is the equivalent statement to "sp_configure 'contained database authentication', 1;"?
The solution is to execute this against the master database of your local/on-premise SQL Server:
sp_configure 'contained database authentication', 1;
GO
RECONFIGURE;
GO
Thank you to David Browne - Microsoft and Alberto Morillo for the quick solution.
I had the same issue and it got fixed by importing the bacpac via command prompt. In link Import Bacpac go to SQLPackage section and run the command provided there.
sqlpackage.exe /a:import /tcs:"Data Source=<serverName>.database.windows.net;Initial Catalog=<migratedDatabase>;User Id=<userId>;Password=<password>" /sf:AdventureWorks2008R2.bacpac /p:DatabaseEdition=Premium /p:DatabaseServiceObjective=P6
The solution that worked for me was to directly copy DB from azure to my localhost.
Create a new database in your local DB server.
Right-click on a new database, Tasks -> Import data.
Provide data for Azure db:
Provide data for your localhost:
Click Next. Check the first checkbox to select all.
On the next form choose -> Run immediately
Wait until the process is completed.
Using the Azure portal to Import a bacpac:
The Collation chosen in the first step of the Azure SQL Import wizard, is important!
It needs to match the Collation in the source DB that was used to create the bacpac.
The sqlpackage and SSMS methods do NOT need this step.

CREATE EXTERNAL DATA SOURCE from SS2019 CTP2.2 not working

So ... I have 2 SQL Server 2019 instances (CTP2.2) and I have one installed with Polybase in single node config (reference this as SS-A). I have created MASTER KEY in the master of SS-A, and created a DATABASE SCOPED CREDENTIAL in a database on SS-A. When I try to do the following:
CREATE EXTERNAL DATA SOURCE acmeAzureDB WITH
(TYPE = RDBMS,
LOCATION = 'ss2019azure.database.windows.net',
DATABASE_NAME = 'dbAcmeAzure',
CREDENTIAL = acmeAzureCred
);
I get an error
Msg 102, Level 15, State 1, Line 6
Incorrect syntax near 'RDBMS'
I have tried to work with MS SQL Server SMEs without any luck (been working on this for many weeks to no avail).
Any ideas here -- plus a message to Microsoft -- your docs on this are AWFUL!!
You have 2 SQL Server 2019 instances (CTP2.2).
But they are not Azure SQL Database instance.
RDBMS External Data Sources are currently only supported on Azure SQL Database.
-- Elastic Database query only: a remote database on Azure SQL Database as data source
-- (only on Azure SQL Database)
CREATE EXTERNAL DATA SOURCE data_source_name
WITH (
TYPE = RDBMS,
LOCATION = '<server_name>.database.windows.net',
DATABASE_NAME = '<Remote_Database_Name>',
CREDENTIAL = <SQL_Credential>
)
Another way, you can create a linked server for your SQL Server 2019 instance to Azure SQL Database. Then you can query data from the Azure SQL DB as EXTERNAL DATA SOURCE.
To see this official tutorial: How to Create a Linked Server.
Reference blob:Incorrect syntax near 'RDBMS'. When I try to create external data source, Anyone having the same issue?
Hope this helps.
SO - worked with MS today - and success -- you can do a CREATE EXTERNAL DATA SOURCE in SS2019 and point to AZURE SQL -- here is the TSQL I used:
(MASTER KEY ALREADY CREATED)
CREATE DATABASE SCOPED CREDENTIAL acmeCred WITH IDENTITY = 'remoteAdmin', SECRET ='XXXXXXXXX';
go
CREATE EXTERNAL DATA SOURCE AzureDB
WITH (
LOCATION = 'sqlserver://ss2019azure.database.windows.net',
CREDENTIAL = acmeCred
);
go
CREATE EXTERNAL TABLE [dbo].[tblAcmeDataAzure]
(
ID varchar(10)
)
WITH (
LOCATION='dbAcmeAzure.dbo.tblAcmeDataAzure',
DATA_SOURCE=AzureDB
);
go

Polybase: Can't connect to Azure Blob from SQL Server

I am trying out the new Polybase-Feature in SQL-Server by connecting to a CSV. However I do not manage to connect to the Azure Blob Storage:
CREATE EXTERNAL DATA SOURCE AzureBlob WITH (
TYPE = HADOOP,
LOCATION = 'wasbs://myfolder#myblob.blob.core.windows.net',
CREDENTIAL = mycredential
);
GO
I always get an error saying:
Incorrect syntax near 'HADOOP'
My SQL Server runs on an Azure VM, however I am not sure which services are supposed to be running:
I also checked TCP/IP is enabled.
I also tried using SSDT and dsql-files as suggested in this post - but the error doesn't go away.
However I do not manage to connect to the Azure Blob Storage
Should it not be a Type=BLOB_STORAGE?
CREATE EXTERNAL DATA SOURCE AzureBlob WITH (
TYPE = BLOB_STORAGE,
LOCATION = 'wasbs://myfolder#myblob.blob.core.windows.net',
CREDENTIAL = mycredential
);
Update 2020-02-18:
I encounter the same famous message recently:
Incorrect syntax near 'HADOOP'
It can be fixed running:
exec sp_configure 'polybase enabled', 1;
GO
RECONFIGURE
Microsoft built a nice page: Configure PolyBase to access external data in Azure Blob Storage. However, they didn't include that important command.
I think it could also be a reason of the initial issue of 5th
While I accepted Alexander's answer, it turns out that the option BLOB_STORAGE doesn't allow to create external tables. The option HADOOP was the correct one for me. There were three steps I needed to do to make the HADOOP option work:
Re-install Java Runtime Environment
Repair the SQL Server Installation
Restart the Virtual Machine
Then the SQL-Statement from my question worked.

Cannot get Linked Servers to work in Sql Azure

We are using a trial version of Azure. We are trying to perform cross server queries from our SQL Server 2012 in-house.
We seem to have our local 2012 linked with Azure. When I go into Server Object -> Linked Servers in management studio, I see our Azure database.
But if I try to open the catalog and tables, I get an error message saying
Reference to database and/or server name in 'Perseus.sys.sp_tables_rowset2' is not supported in this version of SQL Server
** Perseus is the name of our catalog in Azure Sql.
Running a query from local connection:
SELECT * FROM [azureDBServer].[Perseus].[dbo].[accounts]
Tesult is:
OLE DB provider "SQLNCLI11" for linked server "azureDBServer" returned message
"Unspecified error". Msg 40515, Level 16, State 2, Line 1 Reference to database and/or
server name in 'Perseus.sys.sp_tables_info_90_rowset' is not supported in this version of
SQL Server.
This same in house SQL 2012 Server is able to connect to our in-house 2008 by cross server queries and by viewing its structure through Linked Servers.
I know from this article Azure supports Linked Servers.
So I'm lost about what is wrong. Our Admin thinks it may be that we have a Web-Sql account vs a business SQL account. This Azure Web vs Business SQL outdated Stack link implies that SQL version is NOT the problem, but pre-dates when Azure offered Linked Servers.
So, I'm trying to understand if
a) we didn't set up something right to provide SQL Linking?
b) we are limited by trial?
c) are we limited by Web SQL version?
d) anything else?
Need to execute below mentioned three stored procedures to add SQL Azure. Using below these stored procedure I was able to query SQL azure.
EXEC sp_addlinkedserver
#server='PROD',
#srvproduct='',
#provider='sqlncli',
#datasrc='azureserver.database.windows.net',
#location='',
#provstr='',
#catalog='database name'
EXEC sp_addlinkedsrvlogin
#rmtsrvname = 'PROD',
#useself = 'false',
#rmtuser = 'Azure login',
#rmtpassword = 'password'
EXEC sp_serveroption 'PROD', 'rpc out', true
While adding linked server from SQL Management, you are not given option to set default database. So use something like below
EXEC sp_addlinkedserver
#server='name for referring locally', -- here you can specify the name of the linked server
#srvproduct='',
#provider='sqlncli', -- using SQL Server native client
#datasrc='AzureMachineName.database.windows.net', -- add here your server name
#location='',
#provstr='',
#catalog='yourdatabasename'
I figured this works.
Did you actually setup connection to perseus database? By looking at the error message your are sending a query with 3 part or 4 part name to Azure which doesn't work as is in Azure. Please check your query and set it to use 2 part name and only three part name if it is connecting to the same database
This works for me:
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'mypassword';
CREATE DATABASE SCOPED CREDENTIAL MySecurity
WITH IDENTITY = 'mylogin',
SECRET = 'mypassword';
CREATE EXTERNAL DATA SOURCE MyDbAccess
WITH (
TYPE=RDBMS,
LOCATION='server name',
DATABASE_NAME='db_name',
CREDENTIAL= MySecurity);
CREATE EXTERNAL TABLE MyExtTable (
[Id] [int] NOT NULL,
[Name] [varchar(20)] NULL)
WITH
(DATA_SOURCE = MyDbAccess);
After that you can just use it:
SELECT * FROM MyExtTable
I got this error and my issue ended up being a type in the database name SERVER.Database.dbo.tableName.

ALTER DATABASE returning Major Error 0x80040E14, Minor Error 25501

I am attempting to recreate a SQL Server Compact database from a script. I started off creating it like this:
CREATE DATABASE [MyDatabase]
GO
and that seemed to work. The next commands in the script are these:
ALTER DATABASE [MyDatabase] SET ANSI_NULL_DEFAULT OFF
GO
and about two dozen similar commands. I have tried a representative sample of these and they all return the error:
Major Error 0x80040E14, Minor Error 25501
ALTER DATABASE [MyDatabase] SET ANSI_NULLS OFF
There was an error parsing the query. [ Token line number = 1,Token line offset = 7,Token in error = DATABASE ]
Does anyone know what the matter is?
I'm using Microsoft SQL Server Management Studio 2008 R2 on Windows XP.
If you check here - http://msdn.microsoft.com/en-US/library/ms174454(v=sql.90).aspx, I don't think you can do alter database in SQL Server CE.

Resources