What SQL syntax is this? - sql-server

Can anyone tell me what SQL syntax this is please where 123 is the argument passed to the SP?
EXECUTE sp_MyStoredProcedure = '123'
When executing this command the error message from MSSMS is
102, Level 15, State 1, Line 6
syntax near '='.
We need to configure the DB (SQL Server 2008 Express) to accept SQL of this syntax as it is generated by a windows service that we can't change. Trying to set the DB compatibility doesn't work...
ALTER DATABASE ABC SET Compatibility_Level = 80 / 90 / 100
EXECUTE sp_dbcmptlevel 'ABC', 80 --80,90, 100
Thanks in advance

According to the help topic, this syntax is just invalid and apparently never was valid for SQL Server. It looks nonsensical, too. Does it work for some other DBMS?

EXECUTE sp_MyStoredProcedure '123'

The syntax was invalid. The SQL in the windows service was obsolete.

Related

sys.dm_exec_query_stats returns 'invalid column name'

When I execute this statement in SSMS (SQL Server 2012):
SELECT * FROM sys.dm_exec_query_stats
the statement fails and it returns about 20 messages saying
Msg 207, Level 16, State 1, Procedure dm_exec_query_stats, Line 11 [Batch Start Line 0]
Invalid column name 'total_dop'.
Msg 207, Level 16, State 1, Procedure dm_exec_query_stats, Line 11 [Batch Start Line 0]
Invalid column name 'last_dop'.
And so on.
Can anybody explain what's the problem here?
Thanks in advance.
EDIT:
Here's a screenshot:
Your mssqlsystemresource database is out of sync. Looks like manual replacement of the resource database in binn folder, which obviously is not a supported scenario. You must contact MS support to troubleshoot and fix your problem.
Perhaps we can confirm the case, if you run this and post the results:
SELECT SERVERPROPERTY('ResourceVersion');
GO
SELECT SERVERPROPERTY('ResourceLastUpdateDateTime');
GO
SOLVED.
I installed the latest Service Pack and the problem is gone now.
Thank you all for your cooperation and help.
Bliek

RODBCext: SQL 42000 402 Error when using sqlExecute()

I'm working on a Shiny app for updating entries maintained in a SQLServer2008 remote DB. I've been connecting to the DB using RODBC and I'm attempting to use parameterized queries through RODBCext to support mass updates of information.
I'm able to get the parameterized queries to work from my Windows 7, RStudio running R 3.2.3, but for some reasons when I try to run the same code from the linux machine running the same version of R and connecting with the same version of the driver, I get the following error:
Error in sqlExecute(Connection, data = dat) :
42000 402 [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]The data types char and text are incompatible in the equal to operator.
42000 8180 [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Statement(s) could not be prepared.
[RODBCext] Error: SQLExecute failed
In addition: Warning messages:
1: In sqlExecute(Connection, data = dat) :
42000 402 [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]The data types char and text are incompatible in the equal to operator.
2: In sqlExecute(Connection, data = dat) :
42000 8180 [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Statement(s) could not be prepared.
Here is the simple example code that works properly on my windows machine, but not on the linux machine (I removed the connection string information):
library(RODBCext)
Connection <- odbcDriverConnect(paste('Driver=ODBC Driver 13 for SQL Server',
'Server=<Server IP>', 'Port=<Port>', 'Database=<Database>', 'UID = <UserID>',
'PWD=<Password>', sep = ';'))
dat <- data.frame(Node_ID = "999", NodeGUID = "AF213171-201B-489B-B648-F7D289B735B1")
query <- "UPDATE dbo.Nodes SET Node_ID = ? WHERE NodeGUID = ?"
sqlPrepare(Connection, query)
sqlExecute(Connection, data = dat)
In this example, the dataframe is created with the columns as factors. I've tried explicitly casting the columns as characters first, as this seemed to work for the users having trouble with dates, but that still results in the same SQL error. I've also tried casting the Node_ID as numeric to match the SQL table, and I get the same error. The columns in the Nodes table in SQL are defined as:
NodeGUID (PK, char(36), not null)
Node_ID (int, null)
I've tried combining the sqlPrepare and sqlExecute calls by supplying the query argument for sqlExecute, and from what I understand that's a trivial difference and it results in the same error.
I suspect there must be a difference in the drivers and how they implement whatever SQL calls sqlExecute() makes. I also suspect sqlExecute() must handle the data types, as my results don't change regardless of the column types.
Thank you for any help you can provide!
Thanks to everyone who took a look at my question.
One of the SQL Server folks at my job was able to solve the issue. They suggested explicitly casting the arguments in the SQL query written for sqlExecute(). Here's the code that works, note I know the GUID will always be 36 characters and I'm confident the rest of the arguments I use this query for will be less than 1000 when converted to strings:
my_query <- "UPDATE dbo.Nodes SET Node_ID = CAST(? As varchar(1000)) WHERE NodeGUID = CAST(? As varchar(36))"
sqlExecute(Connection, data = dat, query = my_query)
I'm guessing the driver for Windows is somehow handling the casting from text to varchar, but the linux driver does not.
I hope this helps others working with RODBCext. Thanks to Mateusz Zoltak and the team of contributors for a great package!

SQL Server 2012 Change Data Capture Error 14234

I am having problems setting up change data capture on a SQL Server 2012 instance. Whenever I attempt to enable CDC on a table I get the following error:
Msg 22832, Level 16, State 1, Procedure sp_cdc_enable_table_internal,
Line 623
Could not update the metadata that indicates table
[dbo].[TableName] is enabled for Change Data Capture.
The failure
occurred when executing the command '[sys].[sp_cdc_add_job] #job_type
= N'capture''.
The error returned was 22836: 'Could not update the metadata for database [database name] to indicate that a Change Data Capture
job has been added. The failure occurred when executing the command
'sp_add_jobstep_internal'.
The error returned was 14234: 'The
specified '#server' is invalid (valid values are returned by
sp_helpserver).'. Use the action and error to determine the cause of
the failure and resubmit the request.'. Use the action and error to
determine the cause of the failure and resubmit the request.
The name of the server has not changed, I tried the sp_dropserver / sp_addserver solution and receive the following error:
Msg 15015, Level 16, State 1, Procedure sp_dropserver, Line 42
The server 'ServerName' does not exist. Use sp_helpserver to show
available servers.
Msg 15028, Level 16, State 1, Procedure sp_addserver, Line 74
The server 'ServerName' already exists.
As I've stated, I'm trying to set up CDC and not replication. The version of SQL Server is: 11.0.5058.0 (SQL Server 2012 SP2)
I've looked at Error while enabling CDC on table level and tried that solution.
I've also tried:
exec sys.sp_cdc_add_job #job_type = N'capture'
I receive the following error:
Msg 22836, Level 16, State 1, Procedure sp_cdc_add_job_internal, Line 282
Could not update the metadata for database [DatabaseName] to indicate
that a Change Data Capture job has been added. The failure occurred
when executing the command 'sp_add_jobstep_internal'.
The error returned was 14234: 'The specified '#server' is invalid (valid values are returned by sp_helpserver).'. Use the action and error to
determine the cause of the failure and resubmit the request.
Any help would be greatly appreciated.
As listed here, check the names match
SELECT srvname AS OldName FROM master.dbo.sysservers
SELECT SERVERPROPERTY('ServerName') AS NewName
If not, fix with:
sp_dropserver '<oldname>';
GO
sp_addserver '<newname>', local;
GO
The error is caused due to mismatch in value between SERVERPROPERTY(‘ServerName’)) and master.dbo.sysservers
Check these SQLs:
SELECT * FROM master.dbo.sysservers
SELECT SERVERPROPERTY('ServerName')
If your SERVERPROPERTY('ServerName') is not any of the sysservers, then the fix is to change your computer name to match one of those.
Adding the server fixes the issue:
DECLARE #ServerName NVARCHAR(128) = CONVERT(sysname, SERVERPROPERTY('servername'));
EXEC sp_addserver #ServerName, 'local';
GO
I had a similar situation, where I have restored a bak file which I got from another windows machine,which retained windows user account with the old PC name. I had delete the backup, create an empty data base and restore into that. This solved my issue

MEMORY_OPTIMIZED_ELEVATE_TO_SNAPSHOT on SQL Server 2014 CTP1

I am trying to edit this option with the following script:
ALTER DATABASE RIServer
SET MEMORY_OPTIMIZED_ELEVATE_TO_SNAPSHOT ON;
GO
As far as I can tell, the syntax is correct (per msdn). However, I get the following:
Msg 102, Level 15, State 6, Line 9
Incorrect syntax near 'MEMORY_OPTIMIZED_ELEVATE_TO_SNAPSHOT'.
Am I doing something wrong? Is this setting not available on CTP1? Do I need to install CTP2?
I believe that option was added between CTP1 and CTP2.
YOU SHOULD NO LONGER BE USING CTP1. Yes, you need to install CTP2.

PDO DBLib not working

I have a connection with the DBLIB PDO driver, and I am not getting any errors on connecting, but when I run a query an exception is thrown with the error below. I have played around with the syntax of the query as well. I am connecting to a MS SQL server:
SQLSTATE[HY000]: General error: 208 General SQL Server error: Check messages from the SQL Server [208] (severity 16) [SELECT PCO_INBOUNDLOG.PHONE FROM PCO_INBOUNDLOG]
The code:
$sql = "SELECT PCO_INBOUNDLOG.PHONE FROM PCO_INBOUNDLOG";
foreach($this->mssql->query($sql) as $row) {
print_r($row);
}
This is the first time I have ever done a query to a MS SQL server so my syntax may be wrong, any ideas?
First, find out what error 208 means:
select * from sys.messages where message_id = 208
Second, check the FROM syntax (including the examples!) and object identifier rules.
Third, write the query correctly:
SELECT PHONE FROM PCO_INBOUNDLOG
Or, probably better (because it's good practice to include the schema name):
SELECT PHONE FROM dbo.PCO_INBOUNDLOG
Or even:
SELECT p.PHONE FROM dbo.PCO_INBOUNDLOG p

Resources