Trying to enter Diagnostic connection - sql

SQL Server 2014, SP3 Need to establish diagnostic connection. When I open Mgmt Studio, click on database engine query, and type in admin:MSSQLSERVER (we use the default instance on this box) I get:
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'MSSQLSERVER'
Can someone tell me the correct syntax?
I have tried:
admin:servername\MSSQLSERVER
admin:servername
both give same syntax error near whatever is first typed after the colon.

Issue resolved:
When I click on the Database Engine Query button, in the login screen that pops up, put ADMIN: in front of the server name, and connect. This worked for me.

Related

Invalid object name 'sys.dm_exec_input_buffer'

I'm trying to start a script in SQL Server 2014, but it can't find the object in question.
This is the query I am trying to initiate:
SELECT * FROM sys.dm_exec_input_buffer(##SPID, NULL);
Error message:
Msg 208, Level 16, State 1, Line 1
Invalid object name 'sys.dm_exec_input_buffer'.
You need to be on at least Service Pack 2. If you're on an earlier service pack, it's time to patch.
Here's a link to Service Pack 3
Here's a link to the most recent update for SP3
Please apply both, in that order.

Understanding SQL Server kill statement [for non-admin user]

I am looking into how a database management system performs a "cancel" operation when the cancel button is hit on the query. While it doesn't show what query it runs when it does cancel, here is what it shows in the logs:
2019/01/03 22:09:16:433 MSSQL cancelCurrentQuery failed via spid (54). Error: Msg 6102, Level 14, State 2.
User does not have permission to use the KILL statement.
2019/01/03 22:09:16:433 MSSQL cancelCurrentQuery is going to try via dbcancel.
2019/01/03 22:09:16:533 Cancelling current query (finished).
I assume KILL is trying to do KILL {sid} and it fails to do that because of permissions and then calls back to dbcancal. What is dbcancel? And what would be an example of that from the command line?
Additionally, how is it possible for me to kill the queries that I've issued if I cannot use the kill command?
Msg 6102, Level 14, State 2.
User does not have permission to use the KILL statement. (Line 1)

SQL Server Error 208: Invalid object name 'Utils.dbo.ChangeLogging_DDLCommands'

When trying to change the user account to link with the NewMary login:
EXEC sp_change_users_login 'Update_One', 'Mary', 'NewMary'
go
I get the error 208:
Msg 208, Level 16, State 1, Procedure ChangeLogging_LogDDLCommands, Line 147
Invalid object name 'Utils.dbo.ChangeLogging_DDLCommands'.
I don't find any relevant information on ChangeLogging_DDLCommands, and I'm lost at how I do have to proceed from there.
Sounds like you have some kind of custom trigger, which is missing this object.
In SSMS:
Check server triggers under "Server Objects" > "Triggers"
Check individual database DDL triggers under "Programmability" -> "Database triggers"

Why is my Deployment script causing me errors?

I am working on a project in visual studio 2012. Recently, I added a database project to the solution. The database already existed before I added it to the solution and everything worked fine.
Now, however, when I try to run the application I get errors. The errors are being caused by a computer-generated file called [database name].sql. At the top of the tile, it reads:
/*
Deployment script for [the database name here]
This code was generated by a tool.
Changes to this file may cause incorrect behavior and will be lost if
the code is regenerated.
*/
This file gets re-created every time the application runs. The errors that occur appear to be syntax errors. I cannot fix them because any changes I make to the file are irrelevant because a new file gets generated with each run and the errors re-appear.
I tried looking into this more online but had trouble. This is all rather new to me.
Here are some of the errors being created:
GO
:setvar DatabaseName "(the database name is here)"
which gives me three errors that read:
Error 88 SQL80001: Incorrect syntax near ':'.
Error 89 SQL80001: 'DatabaseName' is not a recognized option.
Error 90 SQL80001: Incorrect syntax near '"(the database name is here in the code)"'.
Also, there is a line of code that reads:
CREATE USER [(the domain)\(the username)] FOR LOGIN [(the domain)\(the username)];
GO
which gives the following error:
Error 119 SQL72014: .Net SqlClient Data Provider: Msg 15401, Level 16, State 1, Line 1 Windows NT user or group '(the domain)\(the username)' not found. Check the name again.
From the errors you have posted it looks like there are two issues:
Windows NT user or group '(the domain)\(the username)' not found. - The user being used to access the database doesn't exist. As it's a Windows user I'm guessing that it uses the current user's credentials.
Make sure that your instance of SQL can accept Windows logins and that you (and anyone else building the software) has the necessary access rights.
'DatabaseName' is not a recognized option. - This is more than likely also caused by the first issue, but double check that the database exists.
The error message caught me out recently as it did not relate to the cause of my problem at all. It turns out my SQL script was incorrectly written (for my case - I forgot to add IDENTITY (1,1) to my PK column) to begin with.
Moral of the story for me was to test out the SQL data file in SSMS first.

SQL STATE 37000 [Microsoft][ODBC Microsoft Access Driver] Syntax Error or Access Violation

Good day!
I get this error:
SQL STATE 37000 [Microsoft][ODBC Microsoft Access Driver] Syntax Error
or Access Violation, when trying to run an embedded SQL statement on
Powerscript.
I am using MsSQL Server 2008 and PowerBuilder 10.5, the OS is Windows 7. I was able to determine one of the queries that is causing the problem:
SELECT top 1 CONVERT(DATETIME,:ls_datetime)
into :ldtme_datetime
from employee_information
USING SQLCA;
if SQLCA.SQLCODE = -1 then
Messagebox('SQL ERROR',SQLCA.SQLERRTEXT)
return -1
end if
I was able to come up with a solution to this by just using the datetime() function of PowerBuilder. But there are other parts of the program that is causing this and I am having a hard time in identifying which part of the program causes this. I find this very weird because I am running the same scripts here in my dev-pc with no problems at all, but when trying to run the program on my client's workstation I am getting this error. I haven't found any differences in the workstation and my dev-pc. I also tried following the instructions here, but the problem still occurs.
UPDATE: I was able to identify the other script that is causing the problem:
/////////////////////////////////////////////////////////////////////////////
// f_datediff
// Computes the time difference (in number of minutes) between adtme_datefrom and adtme_dateto
////////////////////////////
decimal ld_time_diff
SELECT top 1 DATEDIFF(MINUTE,:adtme_datefrom,:adtme_dateto)
into :ld_time_diff
FROM EMPLOYEE_INFORMATION
USING SQLCA;
if SQLCA.SQLCODE = -1 then
Messagebox('SQL ERROR',SQLCA.SQLERRTEXT)
return -1
end if
return ld_time_diff
Seems like passing datetime variables causes the error above. Other scripts are working fine.
Create a transaction user object inherited trom transaction.
Put logic in the sqlpreview of your object to capture and log the sql statement being sent to the db.
Instantiate it, connect to the db, and use it in your embedded sql.
Assuming the user gets the error you can then check what was being sent to the db and go from there.
The error in your first statement should be the second parameter to CONVERT function.
It's type is not a string, it's type is an valid expression
https://learn.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql
So I would expect that your
CONVERT(DATETIME,:ls_datetime)
would evaluate to
CONVERT(DATETIME, 'ls_datetime')
but it should be
CONVERT(DATETIME, DateTimeColumn)
The error in your second statement could be that you're providing an wrong datetime format.
So please check if your error still occurs when you use this function
https://learn.microsoft.com/en-us/sql/t-sql/statements/set-dateformat-transact-sql
with the correct datetime format you're using