Not able to restore databases from blob container using T-SQL - azure-blob-storage

I am backing up my databases to an Azure blob storage. I am able to backup and restore from maintenance plan. However I am not able to restore databases with script. Below is the T-SQL I am using:
RESTORE DATABASE database_name
FROM URL = 'https://StorageAccount.blob.core/Container/FileName.bak'
WITH CREDENTIAL = 'https://StorageAccount.blob.core.windows.net/Container', STATS = 10
I am getting this error:
Msg 3225, Level 16, State 1, Line 1
Use of WITH CREDENTIAL syntax is not valid for credentials containing a Shared Access Signature.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
Can you please assist?

You credential is wrong, please follow this link to create a credential.
CREATE CREDENTIAL mycredential
WITH IDENTITY= 'msftutorialstorage', -- this is the name of the storage account you specified when creating a storage account
SECRET = '<storage account access key>' -- this should be either the Primary or Secondary Access Key for the storage account
Then in your restore code, use this credential like below:
RESTORE DATABASE AdventureWorks2016
FROM URL = 'https://msftutorialstorage.blob.core.windows.net/sql-backup/AdventureWorks2016.bak'
WITH CREDENTIAL = 'mycredential',
STATS = 5 -- use this to see monitor the progress
GO

Related

TFS 2018 : TF30042: The Database is Full

Got this Error...
TF30042: The Database is Full. Contact your Team Foundation Server administrator.
Error:1101, Message: could not allocate a new page for database 'Tfs_DefaultCollection' because of insufficient disk space in filegroup 'PRIMARY'. Create the necessary space by dropping objects in the filegroup, adding additional files to filegroup, or setting autogrowth on for existing files in the filegroup.
How to increase size of TFS 2018 database ? Don't have UI to check size and all on server how to change database config through command line?
There is no tool that ships with TFS to alter the files. But any SQL Server management tool will work. I generally use SQL Server management studio to either change the database files directly or to generate the script to change the file size.
Using sqlcmd you can open an interactive session to the database that your TFS server stores all its data in. You can then issue an ALTER DATABASE statement to change the max size of the database.
ALTER DATABASE tfs_defaultcollection
MODIFY FILE
(
NAME = PRIMARY,
SIZE = 50MB
);
Set the new size in the statement above to be big enough. Alternatively, enable auto-growth by setting SIZE = UNLIMITED.

Blob container doesn't allow the creation / reading of an external table. Is there any way to trace the exact problem?

About a month ago, all the external tables built upon parquet files(ADLS Gen2, Synapse) stopped working with the following error message:
Unexpected error encountered checking whether directory exists or not:
AbfsRestOperationException: Operation failed: "Server failed to
authenticate the request. Please refer to the information in the
www-authenticate header.", 401
The access key wasn't rotated and even though I tried recreating new database scoped credentials, data sources, they didn't do anything.
Then I tried creating a new blob container with the same data and I was able to create external tables and run select statements over them.
Does anyone have a clue what the problem could be? At first I thought it was something from Azure, because the coincidence was that they had problems with Synapse. It may seem it's the SAS token, but if it so, why am I not allowed to create other external tables over new SAS tokens? Plus, when a SAS token expires, it throws a 403.
My guess is it is something on configuration for this specific blob, or maybe the Login that I'm using(admin login on SQL Dedicated pool).
From the error it seems to be an authorization issue. If you are accessing the storage account from your synapse studio, the managed identity of your synapse workspace should have storage blob data contributor access on the storage account and container you are trying to access. Giving access using SAS key is not the best option rather use managed identity of your synapse workspace.
You can refer this link step 4 to achieve the same.

How to connect to cosmos db in ruby file

I want to connect to Azure cosmos DB in ruby file, Please can anyone suggest how can I connect with the DB , is there any gem available, to which I can pass connection string of that DB .
Thanks
The following info worked for me, I found it here Connect to CosmosDB using RUBY
If you have not already, first specify connection properties in an ODBC DSN (data source name). This is the last step of the driver installation. You can use the Microsoft ODBC Data Source Administrator to create and configure ODBC DSNs.
You need the following info from CosmosDB
AccountEndpoint: The Cosmos DB account URL from the Keys blade of the Cosmos DB account
AccountKey: In the Azure portal, navigate to the Cosmos DB service and select your Azure Cosmos DB account. From the resource menu, go to the Keys page. Find the PRIMARY KEY value and set AccountKey to this value.
you will need to install the following gems
gem install dbi
gem install dbd-odbc
gem install ruby-odbc
The write something like this
#connect to the DSN
require 'DBI'
cnxn = DBI.connect('DBI:ODBC:CData CosmosDB Source','','')
#execute a SELECT query and store the result set
resultSet = cnxn.execute("SELECT City, CompanyName FROM Customers")
#display the names of the columns
resultSet.column_names.each do |name|
print name, "\t"
end
puts
#display the results
while row = resultSet.fetch do
(0..resultSet.column_names.size - 1).each do |n|
print row[n], "\t"
end
puts
end
resultSet.finish
#close the connection
cnxn.disconnect if cnxn
Since there is no prerequisite from your side in the question, I'm assuming you want to know the complete procedure to work on Azure CosmosDB using Ruby.
You need to create an Azure storage account and Azure CosmosDB account.
The easiest way to create an Azure storage account is by using the Azure portal. To learn more, see Create a storage account.
To create an Azure Cosmos DB Table API account, see Create a database account.
To use Azure Storage or Azure Cosmos DB, you must download and use the Ruby Azure package that includes a set of convenience libraries that communicate with the Table REST services.
Use RubyGems to obtain the package
Use a command-line interface such as PowerShell (Windows), Terminal (Mac), or Bash (Unix).
Type gem install azure-storage-table in the command window to install the gem and dependencies.
Import the package
Use your favorite text editor, add the following to the top of the Ruby file where you intend to use Storage: require "azure/storage/table"
Add your connection string
You can either connect to the Azure storage account or the Azure Cosmos DB Table API account. Get the connection string based on the type of account you are using.
Add an Azure Storage connection
The Azure Storage module reads the environment variables AZURE_STORAGE_ACCOUNT and AZURE_STORAGE_ACCESS_KEY for information required to connect to your Azure Storage account. If these environment variables are not set, you must specify the account information before using Azure::Storage::Table::TableService with the following code:
Azure.config.storage_account_name = "your Azure Storage account"
Azure.config.storage_access_key = "your Azure Storage access key"
Add an Azure Cosmos DB connection
To connect to Azure Cosmos DB, copy your primary connection string from the Azure portal, and create a Client object using your copied connection string. You can pass the Client object when you create a TableService object:
common_client = Azure::Storage::Common::Client.create(storage_account_name:'myaccount', storage_access_key:'mykey', storage_table_host:'mycosmosdb_endpoint')
table_client = Azure::Storage::Table::TableService.new(client: common_client)
Please refer to link if required.

Lost permissions to tables after turning on SQL authorization in Apache Derby

The database created in Java DB (Derby) was set-up as follows to allow authentication and authorization:
CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.connection.requireAuthentication','true');
CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.user.normal', 'normal');
CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.database.fullAccessUsers', 'sa');
CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.database.readOnlyAccessUsers', 'normal');
CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.database.defaultConnectionMode', 'readOnlyAccess');
The "sa" username was created during database creation so it is the owner of the database.
And this works as intended. I can log in as "sa" user and have full access. Or log in as "normal" users and be restricted to read only access.
Now, I want to use SQL authorization to grant specific permissions to specific users.
To do this I have to switch on SQL authorization first by executing following command:
CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.database.sqlAuthorization', 'true');
Problem is, that after login in again under "sa" the system reports that I have no rights for SELECT and other statements. Moreover I loose complete ownership on the database.
Why Derby suddenly denies access to any user including the owner after executing the statement that switches on the SQL authorization?
P.S. I use Apache Derby Network Server - 10.9.1.0 which was a part of Java EE 7 installation for NetBeans 7.3
P.S 2. When after SQL authorization is set to true I try to use GRANT statement I receive following SQL error code:
SQL state 42506: User 'SA' is not the owner of Table/View 'SA'.'DOCTYPES'.
Even though the whole database was created using this username.

How to create a database in Oracle using JDBC?

I want to create a new database on an Oracle server via JDBC. I cannot seem to connect to the database without providing an SID: using a URL like jdbc:oracle:thin:#//[IP]:1521 results in an error of "ORA-12504, TNS:listener was not given the SID in CONNECT_DATA"
Alternatively, if I log into a specific SID, I can run most DDL commands except for CREATE DATABASE foo which fails with an error of "ORA-01100: database already mounted"
How am I supposed to create a database if I cannot connect to the server without specifying a specific database and cannot create a database if I am already logged into a specific database?
AFAIK creating a database needs an internal and direct connection which can only be done by logging in directly on the server (normally a user account called 'oracle').
One reason for that: users are stored in the database itself. No database = no user to connect to by an external client.
Please also note Justin's comment about oracles database schemas. This is probably what you are looking for
What you need are following commands:
CREATE TABLESPACE CREATE USER and few GRANT ... TO ... -- to have rights to connect and create objects, at least

Resources