How to get number of connections for Azure SQL Server? - sql-server

Before dropping a database on an Azure Sql Server I have to check if another user is connected to that db.
Using the stored procedure sp_who2 fails with:
"Could not find stored procedure 'sp_who2'."
Trying to get informations from sys.sysprocesses also fails with message:
"Reference to database and/or server name in 'master.dbo.sysprocesses' is not supported in this version of SQL Server."
How do I get the info I need?

Quick googling found that this approach works quite well in SQL Azure. However it works only in the contexts of a concrete database! Remember that in SQL Azure you can only work with single DB at a time. If you need data from more than one DB you have execute the statement for each DB separately.
Side note, I could not get sp_who working in SQL Azure.
EDIT
The following is screenshot provided for evidence:

Related

How to query Azure Master DB from a Linked Server

I am trying to run this query from an instance on premise to the Master database in Azure.
I can query the other database on the Azure instance with my linked server so that is working and the query I'm trying to run, runs when I log onto the Azure instance.
I just cannot get it to run from my server that has a linked server object set up for Azure.
The code I have tried is:
SELECT [database_id],[name],[Compatibility_level],[collation_name],[state_desc]
,[recovery_model_Desc],[is_broker_enabled],[is_cdc_enabled]
FROM [LinkedServerName].[Master].[sys].[databases]
I have also tried it this way:
EXEC ( 'SELECT [database_id],[name],[Compatibility_level],[collation_name],[state_desc] ,[recovery_model_Desc],[is_broker_enabled],[is_cdc_enabled]
FROM [Master].[sys].[databases]') AT [LinkedServerName]
Again with no success. I am getting this error:
Msg 40515, Level 16, State 2, Line 9
Reference to database and/or server name in 'Master.sys.sp_tables_info_90_rowset_64' is not supported in this version of SQL Server.
Any ideas to help me get around this?
When you created the linked server you specified the user database as the “Catalog” database, you did not specified the master database as the catalog (the database used for the linked server). That is the reason you are using cross database queries, and cross database queries using three and four-part names are not supported on Azure SQL Database as explained here.
Additionally not all sys tables are supported on Azure SQL Database. You will find some DMVs available on Azure SQL Database that do not exist on SQL Server on-premises and vice versa.

Pulling data from Azure SQL database into an Excel through a parameterised stored procedure

I have data in an Azure SQL database, which I would like to pull into an Excel sheet through the use of stored procedure(s) which require parameters.
However, I'm struggling to do this, as I cannot get it to work how it works with a local SQL server. Ordinarily this is done through Microsoft Query, defining the connection to the database, and entering { CALL sproc (?) } and then using the Connections command to map a cell to the parameter.
I cannot set up a connection to the database in MS Query. When I enter the xxx.database.windows.net as the server, my username / password, and then try to switch to database I need to use I get the message below
Filling listbox failed:
SQLState: '37000'
SQL Server Error: 40511
[Microsoft][ODBC SQL Server Driver][SQL Server]Built-in function 'has_dbaccess' is not supported in this version of SQL Server.
Can anyone offer any assistance please?
Create a text file with the .DSN extension then add content like the following into it...
[ODBC]
DRIVER=SQL Server
SERVER=xxxxxxxx.database.windows.net,1234
APP=Microsoft Office 2010
WSID=NA
DATABASE=DB12345
[Microsoft Office]
UID=myUsername
PWD=myPassword
You can then just use this connection from Microsoft Query without dealing with the dialogs that are giving you grief.
I just figured this out with a combination of Youtube videos and dumb luck lol. You have to create an OBDC connection with Microsoft ODBC Driver 13.1 for SQL Server (or higher.) Make sure you connect and define the correct database in the ODBC object while entering in your Azure SQL connection info. Once that's done from within excel you can use MS Query to select that ODBC object and pull the data as you normally would.

SqlServer LocalDB deployed on IIS gives error Invalid object name for Database

I have a MVC 4 application using Sql Server 2012 localDB. Inside the application I am using EntityFramework to access data. I have one raw sql command executing as 'select something from [databasename].[dbo].[something]'.
This query works absolutely fine when running through visual studio. But when deployed on IIS 7 for the same query I get an error 'invalid object name'. Rest all queries and EF commands works fine. I realized that this is due to me qualifying the query with database name. But due to some valid reasons, I need to have databasename in this particular query.
Please help!!!
Is the DB you are trying to connect to on the same server? Is it linked? I am thinking not and that is why you need to qualify the query.
If on a different server you need [servername].[databasename].[dbo].[something] and you need to link to the other server.

Microsoft OLE DB Provider for SQL Server error '80040e14' Could not find stored procedure

I am migrating a classic ASP web app to new servers. The database back end is migrating from SQL Server 2000 to SQL Server 2008, and the app is moving from Win2000 x86 to Win2003R2 x64. I am getting the above error on every single stored procedure call within the application.
I have verified:
Yes, the SQL user is set up, using correct username and password
Yes, the SQL user has execute permissions on the stored procedures in the database
Yes, I have updated the TypeLib references to the new UUID
Yes, I have logged into the database via SSMS with the SQL user id and it can see and execute the stored procedures just fine in SSMS, but not from the web app.
Yes, the SQL user has the database set as its default database.
The most frustrating thing is it works fine on the DEV server, but not on the production server. I have gone through every IIS setting 5 or 6 times and the web app is set up precisely the same in both environments. The only difference is the database server name in the connection string (DEV vs prod)
EDIT: I have also tried pointing the prod web box at the dev database server and get the same error so I'm fairly sure the issue isn't on the database side.
Are you sure that you are really connected to the instance and database you think you are (in the App)? It only takes the wrong DB in the connection string to override the default database for the user.
Can you execute some inline SQL on the connection like:
SELECT ##SERVERNAME AS SERVERNAME
,DB_NAME() AS [DB_NAME]
,CURRENT_USER AS [CURRENT_USER]
It might be the schema. Have you set the default schema of your user in the database you are using?

ODBC problems in SQL 2000 --> 2005 Upgrade

This wiki post outlines both a problem and a solution. I wanted to post this for others that may be having similar problems, as I couldn't find anything specifically to solve this problem elsewhere.
We recently upgraded our SQL Server 2000 database to SQL Server 2005. One of the databases on the server is a back-end to a MS Access database. The MS Access database uses pass-through queries, via DSN-less ODBC to connect to SQL Server.
An example of the DSN-less connection string is shown below:
ODBC; DRIVER=SQL Server;SERVER=servername;APP=Microsoft® Access (Pass Through
Query);DATABASE=databasename;Network=DBMSSOCN;ConnectionTimeout=20;
Trusted_Connection=Yes
After the upgrade, we found that users were unable to run the pass-through queries, and were getting the following error displayed :
ODBC -- connection to 'SQL Server
' failed
This initially appeared to be a permission issue, as elevating the priveledges of the SQL server logins to sysadmin server role alleviated the problem (but obviously this isn't a great solution).
After taking the logins back out of the sysadmin role we found that when connecting to SQL Server via Management Studio, the login could execute the stored procedures. The very same login could not from within MS Access. This pointed to something MS Access was doing while trying to execute the stored procedures - rather than a permission issue.
We ran a trace on the server using Profiler, and this showed up MS Access trying to execute the following command prior to stored proc execution:
DBCC TRACEON(208)
It appeared to fail at this command, prior to stored procedure execution. Research on the web showed that DBCC TRACEON(208) is equivalent to using 'SET QUOTED IDENTIFIERS ON' command, and that in SQL 2005 priveledges to run this DBCC command had been revoked.
After further research, we found references to MS Query having a similar problem, and that the APP component of the connection string should be changed from 'MS Query' to something else.
On a hunch, we changed our APP component of the ODBC connection string, and MS Access no longer tried executing DBCC TRACEON(208) prior to stored procedure execution.
After further testing, we tracked the problem down to the 'copyright' symbol included in the APP component :
APP=Microsoft® Access (Pass Through Query)
By removing the copyright symbol, all was well with the connection and the application worked as it had previously done on SQL 2000.
Hope this helps out anyone else having a similar problem.
Isn't that the registered trademark symbol?
I believe you hit on one of sql server 2005's defences against odbc based attacks. Since there isn't anything on the internet about it, it is likely something MS handled internally.

Resources