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
Related
I am migrating a server that has SQL Server installed - current server Windows 2012 with SQL Server 2012 and target server windows 2019 with SQL Server 2019. Obviously I am trying to mirror the configuration in current server to ensure as few a changes as possible. In the current server, checking the SQL Server Configuration Manager and checking the registry both visually and using script below there does not appear to be a default "MSSQLSERVER" instance setup.
DECLARE #GetInstances TABLE
( Value nvarchar(100),
InstanceNames nvarchar(100),
Data nvarchar(100))
Insert into #GetInstances
EXECUTE xp_regread
#rootkey = 'HKEY_LOCAL_MACHINE',
#key = 'SOFTWARE\Microsoft\Microsoft SQL Server',
#value_name = 'InstalledInstances'
Select InstanceNames from #GetInstances
However, in the current server I can login to SSMS with SA credentials WITHOUT stipulating an instance - that is just using the database engine name and not database engine name\instance, which, unless I am wrong, usually means it connects to the default MSSQLSERVER instance.
Does this mean there IS a default instance setup on current server somewhere? If so how would I find it?
I am wondering how to find out at which port a database running locally in SQL Server 2016 is accepting requests.
The Problem is that the database was set up by a partner, but the port wasn't documented. I tried the default port of 1433, but that did not work.
I also tried using SQL Server Management Studio, but did not find what I was looking for.
You can use this query I have been using:
SELECT DISTINCT local_net_address, local_tcp_port
FROM sys.dm_exec_connections
WHERE local_net_address IS NOT NULL
OR
-- Execute below script if SQL Server is configured with dynamic port number
SELECT local_tcp_port
FROM sys.dm_exec_connections
WHERE session_id = ##SPID
OR
-- Execute below script if SQL Server is configured with static port number
DECLARE #portNo NVARCHAR(10)
EXEC xp_instance_regread
#rootkey = 'HKEY_LOCAL_MACHINE',
#key =
'Software\Microsoft\Microsoft SQL Server\MSSQLServer\SuperSocketNetLib\Tcp\IpAll',
#value_name = 'TcpPort',
#value = #portNo OUTPUT
SELECT [PortNumber] = #portNo
At least one of these will work for you.
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.
The following query is working fine in SQL Server 2008 R2
select *
from openquery(LinkedServerName, 'exec databaseName.dbo.SP_GET_INFO');
I'm trying to convert it using exec command, but no luck.
For instance:
exec ('call databaseName.dbo.SP_GET_INFO') at LinkedServerName
Always getting a syntax error with this message:
Could not execute statement on remote server 'LinkedServerName'
Thanks.
Thanks to #lad2025 for the great help.
Using the following script will work:
exec ('databaseName.dbo.SP_GET_INFO') at LinkedServerName
The first time I tested the code it did not work because of the driver I used to create the linked server.
I have used "Microsoft OLE DB Provider for ODBC Drivers". With this one I got the error:
OLE DB provider "STREAM" for linked server "(null)" returned message ...
The reason was because in the stored procedure I do a select on a nText column which has null values.
So, I changed the driver to "Microsoft OLE DB Provider for SQL Server" and the script worked fine.
Hope this helps someone else.
My Delphi application connects to a SQL Server Database through BDE.
In the process, my application queries SP_Who stored procedure to get the DbName column Value. But now I want to connect my application through ODBC to the SQL Server database.
I'm using the SQL Server Native client driver for this, but when my application queries SP_Who but the procedure does not return the DBName Column. Why is this? How can I get the value of DBName in this case? Is there any other procedure to obtain the DBName column value.
You can obtain the database name using:
SELECT DB_NAME()
Do you get the DBName column running sp_who2 ?