Unable to run SQL Server stored procedure query in SSMS after adding credential parameter - sql-server

I am new to using using stored procedure and Azure storage account. I am exploring the following guide at:
https://www.sqlshack.com/how-to-connect-and-perform-a-sql-server-database-restore-from-azure-blob-storage/
and have created a credential in my database 'Security' > 'Credential' folder in SSMS.
Query that I ran in SSMS:
--using the url and the key
CREATE CREDENTIAL [Credential_BLOB]
WITH IDENTITY= 'https://<account>.blob.core.windows.net/',
SECRET = '<storage account key -> which I enter my Access Key 1>';
Result:
After which I proceed to run the following stored procedure where I want to restore the backup from BLOB storage:
RESTORE DATABASE Database_Name FROM URL = 'https://<account>.blob.core.windows.net/Container/SampleDatabase.bak'
WITH CREDENTIAL = 'Credential_BLOB',
And I get this error:
Msg 41901, Level 16, State 2, Line 3
One or more of the options (credential) are not supported for this statement in SQL Database Managed Instance. Review the documentation for supported options.
However, from the guide which I input the link above, they were able to run the query:
I tried to google for the syntax of the RESTORE statement from the Microsoft Docs library and others who may have encountered similar issue but I did not find any effective result. I would appreciate your help if you have encountered something similar and would like to share your solution. Thank you!

From the error which you have shared, it is easy to interpret that you are using the SQL Database Managed Instance. But the link you have shared doesn't mention anywhere which SQL Server it is using. The approach mentioned in that link might not work in your case because of difference in SQL servers and statement compatibility.
Then, I tried the steps which are given in the Microsoft official document (link shared by #Nick.McDermaid in the comment section). It is working fine without any issue.
Please follow the steps below to achieve the requirement (applicable for SQL Server 2016 (13.x) and later, Azure SQL Managed Instance only).
Use the GUI in SQL Server Management Studio to create the credential by following the steps below.
Connect with your SQL Server 2016 (13.x) and later or Azure SQL Managed Instance
Right-click your database name, hover over Tasks and then select Back up to launch the Back Up Database wizard.
Select URL from the Back up to destination drop-down, and then select Add to launch the Select Backup Destination dialog box.
Select New container on the Select Backup Destination dialog box to launch the Connect to a Microsoft Subscription window.
Sign in to the Azure portal by selecting Sign In and then proceed through the sign-in process. Select your subscription from the drop-drown.
Select your storage account from the drop-down. Select the container you created already from the drop-down. Select Create Credential to generate your Shared Access Signature (SAS). Save this value as you'll need it for the restore.
I also tried to restore the database using the newly created credential and it is working fine.
To create the credential using T-SQL, please follow the steps provided in this link.

Related

Error in SQL Server when connecting to PowerBI Datamart [Unsupported sql function USER_NAME]

I have connected to a Datamart via SSMS. Behind the Datamart is an Azure SQL database.
I am trying to find out my username. I used the following query:
SELECT USER_NAME();
I get this error:
Unsupported sql function USER_NAME. Line:1, Position:8
I have combed the internet but I have not come across something that works yet.
in MS SQL SERVER you must use
SELECT CURRENT_USER;
The op wrote in the comment, that he needed to close the open query box and open a new one, after that it works, like a charme.
or to get the windows user mame of the logged in user
SELECT SUSER_NAME() LoggedInUser

Azure Data Factory fails to execute copy data task to SQL Server

I have an Azure Data Factory pipeline that contains copy data task. The task copies the data from Azure Blob storage to SQL Server Table. The SQL Server is hosted on-prem and hence is accessed through integration runtime.
I tested the connections to both Azure Blob Storage and SQL Server from Azure Data Factory and they work.
However, when I try to execute the copy task I get the following error:
The object (covered in black for confidentiality) is the name of the table I want to write to in SQL Server. I can confirm that the table exists. I can confirm that the user that is the integration run time is using to access SQL server is having the required permissions to write to the table.
This is not an issue with Data factory, as you say your connection is successful it seems to be true.
It more of seems to an issue with either not using the correct database or you do clearly have no access on the table.
Can you use the same database credentials login using SSMS and try running select/update queries?
Also can you check if the auto increment is true?
Please find this link for your reference - > https://support.microsoft.com/en-us/topic/error-message-when-you-try-to-insert-data-into-a-custom-table-in-microsoft-dynamics-nav-cannot-find-the-object-navdbname-dbo-companyname$-tablename-because-it-does-not-exist-or-you-do-not-have-permissions-70dc2a61-c5f7-a85e-ae24-0b4d8931d9ef
A few things you can do to further check if the table is accessible.
Open the related Dataset that is used as 'Sink'
In Connection tab of the dataset, try both 'Test connection' and 'Preview data', as in the image below.
In Schema tab, try the 'Import schema' button, as in the image below.

Bulk Insert failed when executed from remote client but success on local

Please find the diagram as below for my issue:
I have 3 servers in the same domain, there is a SQL Server instance A (it's windows service run under domain\User1), In this instance, we have a Stored Procedure used for BULK INSERT a text file from a network shared folder in server C, the domain\User1 has full permissions on this folder.
My issue is: The Stored Procedure runs ok (green arrow) when connecting by SSMS in its (server A). But it failed when I change to SSMS in server B (log in by the same domain\User1 to the same Instance A). The error is "Access denied" to the text file (red arrow). Does the client have a role in this? I think the client does not matter, the file reading is done from the server (by the user that run Instance A service)
Note: If I connect Instance A from SSMS B with SQL Logon User (not windows account), the stored procedure works fine.
Could anyone give me some advice and sorry for my bad English
This is just a link answer but hopefully it helps.
BTW I commend you for taking the time to analyse the issue to the extent of drawing a diagram. This is far higher quality than most questions on here.
I believe you are running into a double hop issue. I searched everywhere for the BULK INSERT permission model and finally found this https://dba.stackexchange.com/questions/189676/why-is-bulk-insert-considered-dangerous
which says this about using BULK INSERT:
When accessing SQL Server via a Windows Login, that Windows account
will be impersonated (even if you switch the security context using
EXECUTE AS LOGIN='...') for doing the file system access
and this
when accessing SQL Server via a SQL Server Login, then the external
access is done in the context of the SQL Server service account
When you have issues with windows authentication and there is three servers and impersonation, it's often a double hop issue.
This may help you with that:
https://dba.stackexchange.com/questions/44524/bulk-insert-through-network
Which in turn references this:
https://thesqldude.com/2011/12/30/how-to-sql-server-bulk-insert-with-constrained-delegation-access-is-denied/

Transfering Data From Production Server To Development Server

I am want to make the following statement:
INSERT INTO [Server_1\Instance_1].[Database].[dse].Table1
SELECT * FROM [Server_2\Instance_2].[Database].[dse].[**Table1**]
The point is the tables are on the different servers. I tried with the statement above. However, when I am on server_1 and when I run the following statement in order to retrieve the data from server 2:
SELECT * FROM [Server_2\Instance_2].[Database].[dse].[**Table1**]
... I get zero rows.
But when I run the statement above on the Server_2, I get a set of rows.
How can I transfer data from production to development server/environments?
I am using MS Management Studio.
UPDATE:
The error message I am getting when I run the select statement in order to retrieve the data from another (production) server:
The OLE DB provider "SQLNCLI10" for linked server "Prod_Server\Instance" does not contain the table ""Database"."dse"."BoxIteration"". The table either does not exist or the current user does not have permissions on that table.
Select statement is:
SELECT * FROM [Prod_Server\Instance].[Database].[dse].[BoxIteration]
Two things to take into account:
add the source server as a linked server in the destination server
verify that the credentials specified while creating the linked server have access to the data in the source server
I have a localized version of SQL Server, so the transalation may not match what you will see in your screen: open Object Explorer window in SSMS, connect to the destination server, open the tree and look for Server Objects, Linked Servers. Right click on the source linked server, and see the properties. Open the Security pane, and see which credentials are used to connect to the linked server.
Once you do so, you have to check the permissions of that credentials on the source server to verify that it can acccess the table in question.
If you don't understand, or can't do some of the steps (for lack of permissions), get help form your DBA: he will understand and solve the problem at once.
If u have access(Having credentials) to both prod and dev Db servers you can use "Import and Export Data"
1.Go to start and open "Import and Export Data"
Wizard will open give source server name, credentials and Database(For your case Prod)
Then give destination server name, credentials and Database(Dev)
Select the table , if there any identity column -->"Edit Mapping" and Enable identity insert.
Then give next--> it will start copying.

SQL Error: "Cannot use full-text search in user instance."

I'm using SSEUtil to automatically create a functional test database from the schema derived from my development database (SQL Server 2008 R2) as part of my build process. This allows me to keep the two databases in-sync (schema-wise) without running SQL repository tests against my development database.
I recently added a full text index to a table for the first time for this project in my development schema and now when I attempt to apply the schema to a newly created unit test database I get the following error when it executes the SQL to create the full text catalog:
CREATE FULLTEXT CATALOG [FullTextCatalog] AUTHORIZATION [dbo]
GO
Cannot use full-text search in user instance.
[SqlException Number 9982, Class 16, State 100, Line 1]
I've searched high and low. The only help I found was on another site where someone suggested "attaching to the parent database." I have no idea what that means. And I have no idea what this error means. What is a "user instance"?
Can anyone suggest a way around this? Is there a better way to keep two database schemas in-sync for continuous integration?
Either
User must have CREATE FULLTEXT CATALOG permission on the database, or be a member of the db_owner, or db_ddladmin fixed database roles.
or
you won’t be able to use full text catalogues if the SQL instance does not have it installed. Make sure the SQL server instance has the full text service running.
Here are two ways of testing whether this feature installed or not. This feature is available for all editions of SQL Server 2005 and 2008 (including SQL Express)
Check the services applet (run -> type 'services.msc') for this entry :
SQL Server FullText Search Or SQL Server FullText Search (SQLEXPRESS) (in case of SQL Express). Start this service of not running
Run the query "select fulltextserviceproperty('isfulltextinstalled')" in the Query analyzer. if the result is '1' then it is installed else not.
In the case of unavailability of this feature, you need to install by downloading the "SQLEXPR_ADV.EXE" from http://www.microsoft.com/express/sql/download/default.aspx
Reference taken from here
This is not really an answer to the question, but I came upon a similar issue with visual studio package manager when updating an entity framework code-first database (command update-database).
The problem was that I selected the wrong start-up project, and therefore visual studio was not using my connection string at all. It was connecting to a localdb instance, hence the cryptic error message "cannot use full text search in user instance". Once I made it connect to the actual database, it worked as expected.
I also came across this user instance issue. I have to admit that I only have basic knowledge of SSMS. Apparently I'm logged as the public user. How can I be a member of db_owner? I try to generate and script everything without using the GUI.
For example, if I execute this
ALTER AUTHORIZATION ON DATABASE::[dbname] TO sa;
EXEC sp_changedbowner 'sa';
I still get the Cannot use full-text search in user instance error with
USE [dbname]
CREATE FULLTEXT CATALOG [ftc_dbname] AS DEFAULT
GO

Resources