SP_Who does not return DBName Column - sql-server

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 ?

Related

SQL Configure Distribution Connection Issue

I am trying to configure the distribution of SQL Server (2016). This is an Azure SQL VM. However, when doing so I get the following error:
TITLE: Configure Distribution Wizard
------------------------------
SQL Server is unable to connect to server 'COMPANY-SQL'.
SQL Server replication requires the actual server name to make a connection to the server. Specify the actual server name, ''. (Replication.Utilities)
(note it is not actually COMPANY-SQL but a similar naming format). I have tried, as suggested in many posts to sp_dropserver and sp_addserver. This successfully creates ##SERVERNAME set to company-sql-2 which is the name of both my Azure resource (not sure where COMPANY-SQL originates). I'm lost as to how to connect here despite already being connected to the database & why the error says the actual server name is simply ''.
SQL Server is unable to connect to server 'COMPANY-SQL'.
SQL Server replication requires the actual server name to make a connection to the server. Specify the actual server name, ''. (Replication.Utilities)
SERVERPROPERTY: The Windows server and instance name, which together make up the specific server instance, are provided by the ServerName attribute.
##SERVERNAME: The name of the local server as it is set up right now is provided by ##SERVERNAME.
Run the following commands together and you will get two different names.
SELECT SERVERPROPERTY(N'servername')
SELECT ##SERVERNAME
then change the server name by dropping the name got by ##SERVERNAME command with sp_dropserver procedure and set name got by SERVERPROPERTY command with sp_addserver procedure then Restart the SQL Server Service.

Rows from cross-server query on SQL Server table missing, perhaps due to user permissions

I have an Application Server connected to a Database Server (running SQL Server 2014 Express)
I have the following query saved in saveEmails.sql on the Application Server
select
concat('<H3>Email sent: ',send_request_date,'</H3>',body)
from
msdb.dbo.sysmail_allitems
where
send_request_date > dateadd(day, -1, getdate())
order by
send_request_date desc
I have the following saved in a batch file on the Application Server
sqlcmd -S <ip,port> -y0 -U tomcat -P <password> -i saveEmails.sql -o
"C:\temp\saveEmailsOutput.htm"
I did GRANT SELECT ON msdb.dbo.sysmail_allitems to TOMCAT
When I run the query on the database server through SSMS, then I get all the rows in the table.
When I run the query on the application server through sqlcmd, then I only get the rows with sysmail_allitems.send_request_user=tomcat
How can I see all the rows and not just those with send_request_user=tomcat?
msdb.dbo.sysmail_allitems is a view and has Row-level security implemented, which limits the user who is viewing to those rows which were executed by that user.
Run the query instead on msdb.dbo.sysmail_mailitems which is a table and does not have Row-level security implemented.
Note that SQL Server 2014 does not support row-level security on tables, but SQL Server 2016 does.

AzureSQL- Could not find stored procedure 'sp_configure' while installing Sitecore9.1

I am installing Sitecore9.1 with powershell using Azure SQL server and databases. While running script, it creates databases and while creating/updating MarketingAutomation databases it is giving error about 'contained database authentication'
error is - The command started with the following:
"exec sp_configure 'contained database authenticati"
Could not find stored procedure 'sp_configure'.
Install-SitecoreConfiguration : Command C:\Program Files\iis\Microsoft Web Deploy V3\msdeploy.exe returned a non-zero exit code - (-1)
I am running below command to Azure SQL server for this issue:
sp_configure 'contained database authentication', 1;
GO
RECONFIGURE;
GO
but while executing it throws error about syntax.
I could not find commands for AzureSQL or SQL2017 for contained database authentication.
I want commands for contained database authentication for Azure SQL.Please help.
sp_configure is not available on Azure SQL Database and you should use ALTER DATABASE SCOPED CONFIGURATION instead to configure Azure SQL Database options and parameters.
The following query should tell which databases have contained database authentication enabled.
select [name] as databasename, containment, containment_desc from sys.databases
As you can read on this documentation, the containment value of zero applies to Azure SQL Database, but value1 cannot be set on Azure SQL Database. However you can create contained database users on Azure SQL Database without the need to enable containment, and the contained database user model is the recommended model instead of the traditional connection model as mentioned here.

Powershell invoke_sqlcmd is not closing connection

I am using Powershell to a script to dynamically restore a database (sql server 2012).
set-location "SQLSERVER:\sql\$host_name\$inst\databases\.$db_target"
$db = Invoke-Sqlcmd -Query "select type_desc,name,physical_name from sys.master_files where database_id=db_id(N'$db_target') order by type_desc desc "
When I execute the script I get the following error message :
DBMS MSG - ODBC return code <-1>, SQL State <37000>, SQL Message
<3101><[Microsoft][SQL Server Native Client 10.0][SQL Server]Exclusive
access could not be obtained because the database is in use.>.
I then use SSMS to make the database offline
alter database [db_target] set offline with rollback immediate
After this my script works fine.
Question :
Why is invoke_sqlcmd not closing the session?
Can I execute the alter database .... command from my powershell script?
Thanks

xp_regread SQL Server 2012

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

Resources