Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 407
emalcolmb Avatar asked Jul 30 '19 00:07

emalcolmb


3 Answers

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

like image 187
emalcolmb Avatar answered Nov 13 '22 21:11

emalcolmb


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.

like image 44
Taylor G Avatar answered Nov 13 '22 20:11

Taylor G


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.

like image 1
STEFAN SCHUEPFER Avatar answered Nov 13 '22 20:11

STEFAN SCHUEPFER