SQL Server Invalid version: 15 (Microsoft.SqlServer.Smo)
Asked Answered
O

4

55

Context: I'm having difficulty modifying a stored procedure in SQL Server 2016. The stored procedure performs parsing of json data within a file. For some reason I'm able to execute the stored procedure and it executes successfully but when I try to modify the stored procedure I get the following message:

enter image description here

Question: Does anyone have any troubleshooting tips? Below is the content of the stored procedure. SQL Server 2016 supports the various functions used including the OPENJSON function.

USE mattermark_sandbox
GO

CREATE PROCEDURE get_company_data 

AS

IF OBJECT_ID('tempdb..##jsondump') IS NOT NULL DROP TABLE ##jsondump
IF OBJECT_ID('tempdb..##jsonparsed') IS NOT NULL DROP TABLE ##jsonparsed
IF OBJECT_ID('tempdb..##json_loop') IS NOT NULL DROP TABLE ##json_loop

CREATE TABLE ##jsondump (
    [my_json] [nvarchar](max) NULL
) 

-- Create a table to house the parsed content
CREATE TABLE ##jsonparsed (
    [id] [int] NULL,
    [url] [varchar](255) NULL,
    [company_name] [varchar](255) NULL,
    [domain] [varchar](255) NULL
)

-- Clear ##jsondump
TRUNCATE TABLE ##jsondump;

-- Clear ##jsonparsed ( only if you don't want to keep what's already there )
TRUNCATE TABLE ##jsonparsed;

-- Import ( single column ) JSON
--IMPORTANT: Need to be sure the company_data.json file actually exists on the remote server in that directory 
BULK INSERT ##jsondump
FROM 'C:\mattermark_etl_project\company_data.json' -- ( <-- my file, point to your own )
WITH (
    ROWTERMINATOR = '\n'
);

-- Select JSON into ##jsonparsed
SELECT my_json 
INTO ##json_loop
FROM ##jsondump;

--SELECT * FROM ##jsondump;

INSERT INTO ##jsonparsed (
    id, [url], company_name, domain
)
SELECT DISTINCT
    jsn.id, jsn.[url], jsn.company_name, jsn.domain
FROM ##json_loop
OUTER APPLY (

    SELECT * FROM OPENJSON(##json_loop.my_json, '$.companies' )
    WITH (
        id INT '$.id',
        [url] VARCHAR(255) '$.url',
        company_name VARCHAR(255) '$.company_name',
        domain VARCHAR(255) '$.domain'
    )

) AS jsn

DECLARE @bcp_cmd4 VARCHAR(1000);
DECLARE @exe_path4 VARCHAR(200) = 
    ' cd C:\Program Files\Microsoft SQL Server\100\Tools\Binn\ & ';
SET @bcp_cmd4 =  @exe_path4 + 
    ' BCP.EXE "SELECT ''Company_ID'', ''MatterMark_URL'', ''Company_Name'', ''Domain'' UNION ALL SELECT DISTINCT cast(id as varchar( 12 )) as id, url, company_name, domain FROM ##jsonparsed" queryout ' +
    ' "C:\mattermark_etl_project\company_data.txt" -T -c -q -t0x7c -r\n';
PRINT @bcp_cmd4;
EXEC master..xp_cmdshell @bcp_cmd4,no_output;

SELECT DISTINCT * FROM ##jsonparsed
ORDER BY id ASC;

DROP TABLE ##jsondump 
DROP TABLE ##jsonparsed 
DROP TABLE ##json_loop 

/*
-- To allow advanced options to be changed.  
EXEC sp_configure 'show advanced options', 1;  
GO  

-- To update the currently configured value for advanced options.  
RECONFIGURE;  
GO  

-- To enable the feature.  
EXEC sp_configure 'xp_cmdshell', 1;  
GO  

-- To update the currently configured value for this feature.  
RECONFIGURE;  
GO  
*/

exec xp_cmdshell 'C:\mattermark_etl_project\powershell "C:\mattermark_etl_project\open_file.ps1"',no_output

Osric answered 30/7, 2019 at 0:16 Comment(7)
At what stage in the operation are you receiving this error? When you hit execute?Condemnatory
Your code doesn't show anything being modified? Its showing a create statement?Condemnatory
Are you 100% sure that your SQL Server, and SSMS versions are both 2016? SSMS allows you to connect to any database version. The error would imply that the script includes unsupported features in either database engine or management studio. Try select @@versionCondemnatory
Seems like you might be trying to talk to a SQL Server 2019 database using SSMS 2016.Condemnatory
Turns out I'm actually running SQL Server 2019 CTP 2.5 which should support the features needed in the proc. I'm usingf SSMS v18.0.Osric
Yeah, but what will be happening is that for some functions SSMS doesn't have the capabilities to properly interact with the database engine because its a newer version. If you upgrade SSMS to the same version all should be well.Condemnatory
Using SSMS version 18.0 instead of 17.0 seems to be working.Osric
O
49

Using SSMS version 18.0 instead of 17.0 seems to be working.

You can download it from https://learn.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms?view=sql-server-2017

Osric answered 1/8, 2019 at 0:10 Comment(5)
Unfortunately SSMS 18 doesn't support Debugging T-SQL, and it's a huge pain to install VS to use SSDT to debug sprocs (and many people report SSDT currently hangs when debugging T-SQL on SQL Server 2019, joy).Mosstrooper
Everybody, please sign this user voice related item here to help its way back to SSMS: feedback.azure.com/forums/908035-sql-server/suggestions/…Bertero
Why the F should I need SSMS 18.0 to look at the definition of a proc? Makes no sense. As per Dai, lack of debugging is just junk. So frustrating.Allare
Agreed! 👍@shivOsric
@hamidreza looks like the user voice link is broken, can you post an updated link? (Or an update on the situation if it's solved? -- I would love to vote on it if it's not though.)Louralourdes
B
21

You can use a query to view the stored procedure definition without installing a new SSMS. Before running this query, you can optionally use the SSMS menu item Query -> Results To -> Results to Text to format the result in one text field.

exec sp_helptext [get_company_data]

(Where get_company_data is the stored procedure name.)

Also note that the stored procedure 'Modify' option just opens a regular query tab pre-filled with the definition as an ALTER PROCEDURE, you can instead update it by running an ALTER PROCEDURE in a normal query tab.

Blumenthal answered 1/9, 2021 at 20:20 Comment(0)
B
4

There is a workaround for this issue: Instead of selecting Modify, right klick on the database name and select Tasks> Generate Scripts: Select Specific Objects, Check your object.

Berrie answered 2/11, 2022 at 10:12 Comment(0)
R
-2

If you are using the Oracle server. Then use OPENQUERY. Select Syntax as follows:

  select * from OPENQUERY(LINK_SERVER_NAME,'select * from DUAL')  
Retroact answered 6/11, 2022 at 7:18 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.