Single user restrictions even if nobody's connected - sql-server

When using SQL Server Management Studio I try to query a DB created with "Single user" restrictions.
I log in by using SQL Credentials and "sa" user and by running sp_who2 command I double check nobody is connected to the DB, nevertheless when executing a query on a DB table, the system replies:
Database 'MyDB' is already open and can only have one user at a time.
I'd like to understand why I am experiencing this issue.
Can anybody help on this?

When you set a db in "single user" mode you can only open a single connection to the database (more info here).
So when you open SSMS to navigate through database objects you open the only permitted connection. After this any other operation that requires a new connection to the db will fail, for example creating a new query window to write a query.
From MS Docs:
When you start an instance of SQL Server in single-user mode, SQL Server Management Studio can connect to SQL Server. Object Explorer in Management Studio might fail because it requires more than one connection for some operations. To manage SQL Server in single-user mode, execute Transact-SQL statements by connecting only through the Query Editor in Management Studio, or use the sqlcmd utility.
The same happens on premise if you have the SQL Server agent running.
Another advice from MS Docs (if you are running SQL Server on premise):
Stop the SQL Server Agent service before connecting to an instance of SQL Server in single-user mode; otherwise, the SQL Server Agent service uses the connection, thereby blocking it.

Related

RING_BUFFER_CONNECTIVITY - LoginTimers - Error 17830 logs when releasing unused database connection in MSSQL

I have this program that uses QLOLEDB (also tried using the MSOLEDBSQL) to connect to local sql server express 2014 (ver 12.0.2). The program always creates 2 connections, one for IDBCreateCommand and one for iOpenRowset which is used for fastload. The program is functioning well but it keeps on creating RING_BUFFER_CONNECTIVITY LoginTimers logs in sys.dm_os_ring_buffers when I try to release the database connections. No error were created in SQL server logs.
Using the SQL profiler, I know that the logging of RING_BUFFER_CONNECTIVITY happens during Audit Logout of the database connection, though I have 2 connections, only one of them is creating the RING_BUFFER_CONNECTIVITY log and it only happens when releasing connections that were not use (does not matter if it is using IDBCreateCommand or iOpenRowset). Using connections for running SQL query will not log RING_BUFFER_CONNECTIVITY when they are released.
The issue is also happening in MS SQL server 2016 express (ver 13.0.4001) but not in MS SQL server 2012 express(ver 11.0.5058), I am really running out of ideas as to what is causing this. Is there some added feature in SQL server 2014 and later versions that warns user of unnecessary database connections that were created? Like connections that were created but not even use? (I tried proving this by creating database connections using MS SQL management studio then closing it afterwards and it does not create a RING_BUFFER_CONNECTIVITY log... but looking at the sessions created using OLEDB and MS SQL management studio in sys.dm_exec_sessions.. sessions created using OLEDB has memory_usage = 0, while the latter has memory_usage = 3).
What am I missing?
Attached is the sample record created in sys.dm_os_ring_buffers.

Connect from application to SQL Server (ONLY Theoretical!)

I don't know how to connect from a self-written application to a SQL Server. I have added an application role to the SQL Server already. Do I need a SQL Server login or only a database user? I know that after I'm connected I can run the procedure sp_setapprole to access the database as an application. How does this work in theory?
You need a connection string
(instructions on how to connect to the SQL Server: URL,PORT,USERNAME,PASSWORD) and a command to be Executed.
I'm sure there are a lot of instructions online for you, just give it a quick google search:
%Programming_Language & "SQL Connection String"

How do I resolve encryption error connecting to SQL Server from Oracle SQL Developer

My objective is to use the migration tool in SQL Developer to migrate 2 SQL Server databases to Oracle. I am attempting to connect to a SQL Server database at a remote location using Oracle SQL Developer 4.0.
I have installed jtds.1.3.0.jar per instructions, and get the SQL Server and Sybase tabs in the connection properties window.
I have entered the user, pw, hostname, port, and database name. When I try to Retrieve Database, or connect, I get the error message:
Status : Failure -Test failed: I/O Error: DB server closed connection.
The SQL Server DBA tells me her error logs contain the following error message:
Encryption is required to connect to this server but the client library does not support encryption; the connection has been closed. Please upgrade your client library. [CLIENT: (my computer's IP address)] Error: 17835, Severity: 20, State: 1.
When I look at SQL Server documentation about this error message, it talks about certificates and SQL Server Connection Manager. Some relevant information to show that I've covered the basics:
Using the same connection parameters, I am able to connect to the SQL Server database using Toad for SQL Server.
Using the same connection parameters, a DBA set up an Oracle Transparent Gateway, and I can connect to the SQL Server database using the gateway and a database link. (As far as I know, neither of these methods required a certificate to connect.)
Both of these use ODBC; SQL Developer uses jdbc with TCP/IP.
The DBA assures me TCP/IP connection is turned on for the SQL Server databases.
I have gone into the XML file where SQL Developer stores the connection string. It has the form jdbc:jtds:sqlserver://sql-xxx-xxx.mw.nos.xxx.com:1433/my_db, which looks correct. I have tweaked it by adding the instance name, but no difference. The database has a default instance name, anyway, so it shouldn't be necessary.
A co-worker has been able to connect to a local SQL Server database on the same machine where SQL Developer was running (both on his laptop).
As a workaround, I am also pursuing the possibility of installing SQL Server on a local workstation, and copying the databases there for processing, but I don't know if I can get approval. If you know another tool for migrating from SQL Server to Oracle, please also let me know.
Thanks in advance.

SQL Server 2012 remote restart or stop service

I want to remote restart or stop SQL server service on SSMS. When I login in a DB using sa account, the menu bar still be disabled
I looked up some information, MS seems to disable it for security reasons from SQL server 2012
If there is any possible, I can alter some system settings to do that?
So to stop/restart an SQL Server instance from Object Explorer in SSMS, you would have to met the following requirements:
1. You must have to have at least public server role on the SQL Server instance.
2. You must have the privilege to start/stop services on the server that hosts SQL Server instance. For example, add your windows user to administrator group on the server.
Also,since SA uses SQL authentication, the best you can do is issue a SHUTDOWN command to stop SQL Server.

Moving MSDB, can't access single user mode

I am attempting to move msdb (SQL Server 2005) by using the instructions here:
http://support.microsoft.com/kb/224071
However, when I start SQL Server in single user mode, I have no way to access the database. I have tried starting sqlcmd from the console (and also for good measure tried starting ssms), but I'm unable to get into any tool to do my work because it says it is in single user mode and only one administrator can be logged in. In the services console I see no other SQL Server related processes running, so what is preventing me from getting in?
Thanks...
Some application is stealing the only connection available. See Starting SQL Server in Single-User Mode for a tip how to prevent that:
When you use the -m option with sqlcmd or Management Studio, you can
limit the connections to a specified client application. For example,
-m"sqlcmd" limits connections to a single connection and that
connection must identify itself as the sqlcmd client program. Use this
option when you are starting SQL Server in single-user mode and an
unknown client application is taking the only available connection. To
connect through the Query Editor in Management Studio, use
-m"Microsoft SQL Server Management Studio - Query".

Resources