I am trying to create a sql database using cloud shell
Note: I am able to create the sql database in the same resource group without any issues.
When i execute the command from the the cloud shell I get the following error message.
PS /home/xxx> az sql db create -g akshandsonlab -s aksdatabase -n mhcdb --service-objective S0
ResourceNotFoundError: The Resource 'Microsoft.Sql/servers/aksdatabase' under resource group 'akshandsonlab' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix
I have followed the above link but I am reaching a dead end.
Can any one shed some light on this
Regards
Sudlo
You could check if you have selected the correct subscription when you create the SQL database via az account show.
If not, you could list the subscription(az account list) then set the subscription(az account set -s <subscriptionID>) that you want to create the resource.
If not, you could double-check the Resource name and Resource group name.
For more information, please refer to https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/error-not-found
Note: I am able to create the sql database in the same resource group
without any issues.
It looks like you want to create your database in a different resource group than that of your SQL server, which is not possible as of today. The SQL server and DB must exist in the same resource group.
This is most likely the reason you're seeing this error. Instead, run the command passing the resource group where your SQL server exists.
az sql db create -g <sql-server-resource-group> -s aksdatabase -n mhcdb --service-objective S0
Related
I am a bit struggling to find the best approach to achieve this.
I am trying to achieve a full automated process to spin up a Microsoft sql server, a SQL Database using terraform, and ultimately, when I have all the infra in place, to release a *.dacpac against the SQL Database to create tables and column and ultimately seed some data inside this database.
So far I am using azure pipeline to achieve this and this is my workflow:
terraform init
terraform validate
terraform apply
database script (to create the tables and script
The above steps works just fine and everything falls in place perfectly. Now I would like to implement another step to seed the database from a csv or excel.
A did some research on google and read Microsoft Documentation but apparently there are different ways of doing this but all those approaches, from bulk insert to bcp sqlcmd, are documented with a local server and not a cloud server.
Can anyone please advice me about how to achieve this task using azure pipeline and a cloud SQL Database? Thank you so so much for any hint
UPDATE:
If I create a task in release pipeline for cmd script. I get the following error:
2021-11-12T17:38:39.1887476Z Generating script.
2021-11-12T17:38:39.2119542Z Script contents:
2021-11-12T17:38:39.2146058Z bcp Company in "./Company.csv" -c -t -S XXXXX -d XXXX -U usertest -P ***
2021-11-12T17:38:39.2885488Z ========================== Starting Command Output ===========================
2021-11-12T17:38:39.3505412Z ##[command]"C:\Windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "D:\a\_temp\33c62204-f40c-4662-afb8-862bbd4c42b5.cmd""
2021-11-12T17:38:39.7265213Z SQLState = S1000, NativeError = 0
2021-11-12T17:38:39.7266751Z Error = [Microsoft][ODBC Driver 17 for SQL Server]Unable to open BCP host data-file
It should be actually quite simple:
The following example imports data using Azure AD Username and Password where user and password is an AAD credential. The example imports data from file c:\last\data1.dat into table bcptest for database testdb on Azure server aadserver.database.windows.net using Azure AD User/Password:
bcp bcptest in "c:\last\data1.dat" -c -t -S aadserver.database.windows.net -d testdb -G -U alice#aadtest.onmicrosoft.com -P xxxxx
If you do not plan use AAD account - please remove -G flag.
Ideally it would be if you put your admin account name and password into terraform directly from terraform. The you can fetch those values vie KeyVault task in the pipeline and use to run above mentioned script.
It looks that bcp is already on windows agents:
I'm trying to create a SQL Server using ARM Template.
While executing it, its throws an error of:
Server Name already exists
but it does not.
I tried deploying it in many subscriptions and resource group of different regions but outcome is always same.
I'm calling resource group name as SQL Server name using [resourceGroup().name].
Also, along with SQL Server, Vnet,Nsg,Local Network Gateway, VPN Gateway is deployed using resource group but are created successfully.
The SQL Server name must be unique for all of Azure, not only within your subscription.
You get a fully qualified domain name for it, so you need a unique name:
yourservername.database.windows.net
Azure SQL server name should be universal unique not for your subscription
I have created pipeline using Azure DevOps for Azure PostgreSQL database.
What actually pipeline do?
Connect to PostgreSQL;
Remove database db_test from PostgreSQL using Azure CLI;
az postgres db delete -g my_group -s database_here -n db_test --yes
However, I cannot do this due to error:
An unexpected error occured while processing the request.
Then, I was trying to remove the database using psql, but with no luck due to existing connections to database.
From my point of view - Azure CLI must handle such issues and remove database or pass correct error message to me. For example it would be great if parameter --force will be implemented.
I have removed all connections to database using the following syntax in a bash script:
psql "host=database_here port=5432 dbname=postgres user=postgres#database_here password=ReallyStrongPassword sslmode=require" -c "REVOKE CONNECT ON DATABASE db_test FROM PUBLIC; SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'db_test';"
and added DROP database action additionally to my pipeline:
psql "host=database_here port=5432 dbname=postgres user=postgres#database_here password=ReallyStrongPassword sslmode=require" -c "DROP database db_test;"
But I didn't remove AZ CLI database removal step from pipeline and it has failed with the following output:
Operation failed with status: 200. Details: Resource state Failed
I think on this step, AZ CLI should return something like: "Database does not exist." just as informative message.
How to properly handle such situations on the Azure side?
Does az postgres db show show the database details? Please check if this is happening due to this behaviour, albeit the discussion in the quoted thread is in context with a SQL database.
If the issue still persists, please feel free to drop your feedback here open an issue with our GitHub repo for our internal Team to take a look at.
Thanks for the feedback!
I am looking at creating a sql server failover group using the azure cli. The following command is being used :
az sql failover-group create --name sql1-fg --resource-group sql1 --server sql1 --partner-server sq1l-dr --partner-resource-group sql1-dr --failover-policy Manual
However I get the following error :
Grace period value should not be provided when failover policy Manual
is selected for the read-write endpoint
I have not passed in this parameter but with grace-period being a default parameter with a value of 1, my query is how do I exclude this from the command line. I have tried setting to 0, -1, $false, $null, etc.
I can reproduce your issue on my side, I think it may be a bug of Azure CLI, because it is unreasonable.
Even if I create the failover group with Automatic first, then use the az sql failover-group update to set the --failover-policy to Manual, it always gives the same error message.
I have opened a new issue in the Github, you could check it. Or you could create the Automatic group first, and set it to Manual in the portal.
I have an SQL database in Azure that I use with my API. I can access the database from SQL Server Management Studio, and it seemto be alright - I can select data, make modifications and whatever. Although, I can't access it from Azure Portal.
It doesn't appear when I list all resources in the Azure portal
When I select the database server from Azure Portal, I can see it under the list of available databases. When I click the specific database, I get the following error message:
"This resource was not found, it may have been deleted. /subscriptions/aee8966e-5891-40fb-8fff-8c359f43baee/resourceGroups/TestResourceGroup/providers/Microsoft.Sql/servers/testdbserver/databases/testdb"
Any ideas?
Update 2018-05-16:
Jerry Liu suggested renaming the database, so I logged into SQL Server Management Studio, and this is what I found:
I wasn't allowed to rename any of the databases on the server using right click --> Rename. The option is disabled.
ALTER DATABASE carbonate_prod_180508 Modify Name = carbonate_renamed;
Running this command, I get the error message "The source database 'carbonate_prod_180508' does not exist.". But I do see the database listed in the Object Explorer.
I also tried renaming it using Azure CLI. I find the database using "az sql db list" with the resource group name and server name, but when i run "az sql db rename" I get an error message stating the database was not found.
If you have done some operation like delete and recreate with same name or just move to another resource group, please wait a while for the operation to work completely.
Or if you have done nothing related, please try to rename your database in Management Studio and visit portal to check whether it's "back".
How to Rename SQL DB
Two methods for you to try
Click on database name twice slowly, or click once and push F2, just like we rename a file locally on Windows.
Create query on master database to execute alter operation.
Wait for about 30 seconds and refresh portal.
If none of them works, I recommend you to new a support request to Azure Team. It's the last blade in your Azure sql server panel.