I have an Azure SQL Database. I am trying to execute the following query on SQL Server Management Studio 2016:
ALTER TABLE Contacts ADD UserId nvarchar(128)
DEFAULT CAST(SESSION_CONTEXT(N'UserId') AS nvarchar(128))
I get the following error:
Msg 195, Level 15, State 10, Line 22
'SESSION_CONTEXT' is not a recognized built-in function name.
I am following this row level security tutorial: https://github.com/Azure/azure-content/blob/master/articles/app-service-web/web-sites-dotnet-entity-framework-row-level-security.md
You have to upgrade your SQL Server on Azure portal to V12. I think this could work.
Related
We're having trouble with running SQL 'exec' but if we run 'select' we don't have a problem.
We had Win 2012 Servers with SQL Server 2014 -
We are upgrading WinOS and SQL version, so now have identical servers with Win2019 + SQL 2017 Server v14.0.3436.1
We restored the databases from the old servers to the new servers
We have a linked server setup, and we can run the following 'select' command against the remote server and it works fine and returns results.
i.e.:
select * from CSDB23.systemlive.dbo.dt_currency
However when we run the 'exec' command:
exec csdb23.systemlive.dbo.p_transfer 3,'SystemProd1'
we get the following issue:
Msg 7202, Level 11, State 2, Procedure systemlive.dbo.p_transfer, Line 31 [Batch Start Line 0]
Could not find server 'CSDb23' in sys.servers. Verify that the correct server name was specified."
We see support issues suggested we drop and add the server using commands from SQL Server 2016 (but the commands given are depreciated from SQL 2016 so not relevant in 2017
sp_dropserver 'Server_A'
GO
sp_addserver 'Server',local
GO
but the linkserver is already setup:
[
A bit lost on how or what I need to check so we don't get this issue?
Thank you
We found the issue to be with the Server Name.
When the server was created in Azure, it was created with a Market Place image with SQL already a part of the image.
The server was named (just an example) "Sever-DB10". Once the servers were deployed, the name of the sever was changed to "MainDB10" - However, the SQL instance was still seeing the server as "Server-DB10" when we looked up the names of the SQL instances using:
select name from sys.syservers
We see the server was referencing the old name of the server and not the new name. We manually dropped the name and readded it back via the linked server with the correct name. - we no longer then had the main issue "Cannot find server X)
(We hada raft of other Access issues after this and eventually reinstalled SQL which seemed to completely resolve all issues we had.)
I'm trying to create a security policy with this query:
CREATE SECURITY POLICY Security.DegreeFilter
ADD FILTER PREDICATE Security.fn_securitypredicate(Degree) ON Students
WITH (STATE = ON);
But I get this error:
Msg 343, Level 15, State 1, Line 1
Unknown object type 'SECURITY' used in a CREATE, DROP, or ALTER statement.
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near 'FILTER'.
I'm using SQL Server 2014 SP3.
SELECT ##version returns Microsoft SQL Server 2014 (SP3).
compatibility_level for my database is 120.
According to the Documentation
CREATE SECURITY POLICY only applies to SQL Server 2016 (13.x) and later
I'm trying to set up transactional replication in SQL Server 2012 using AdventureWorks 2012. And right at the end of the publications setup i get the following error:
SQL Server could not start the Snapshot Agent.
Additional Information:
An exception occurred while executing a Transact-SQL statement or batch.
(Microsoft.SqlServer.ConnectionInfo)
SQL ServerAgent is not currently running so it cannot be modified of this action.
Changed database context to 'AdventureWorks2012'.(Microsoft SQL Server,Error 22022)
I'm guessing this error isn't allowing me to execute the following code:
USE ADRepl;
SELECT * FROM Person.BusinessEntity
As every time I do execute this I get the following error:
Msg 208, Level 16, State 1, Line 2
Invalid object name 'Person.BusinessEntity'.
Make your sql agent property as automatic.
Set the SQL server agent service Automatically.
Press windows key+R
type services.msc
right Click on sql server agent
properties >> startup >> select automatically.
I made a full database backup. I wanted to restore this database in another distant machine.
However, database restoration failed with:
Msg 7202, Level 11, State 2, Server MySERVER\SQLEXPRESS, Procedure _SBOF_FOO1, Line 17
Could not find server 'svr1' 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.
Aparently, there is a store procedure that has a reference to a server 'svr1' which cannot find. How to work around this error?
I am trying to use xp_regread on a new SQL Server 2012 server I have just installed.
Previously, I have used a query like the following on SQL Server 2008 servers to get the account running the current instance:
declare #regResult varchar(20)
exec master..xp_regread #rootKey = 'HKEY_LOCAL_MACHINE',
#key = 'SYSTEM\CurrentControlSet\Services\MSSQLSERVER',
#value_name = 'ObjectName',
#value = #regResult OUTPUT
select #regResult
However, I now get the following error when using the same query on SQL Server 2012:
Msg 22001, Level 15, State 0, Line 0
Error executing Read extended stored procedure: Invalid Parameter
I am assuming xp_regread has changed in SQL Server 2012. Does anyone know how it changed?
I am also open to a different query that doesn't use an extended stored procedure to get the service account running the instance.
How about
select * from sys.dm_server_services
http://msdn.microsoft.com/en-us/library/hh204542.aspx