Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stored Procedures not working in Linux version of SQL server? #783

Open
TSS3005 opened this issue May 12, 2023 · 0 comments
Open

Stored Procedures not working in Linux version of SQL server? #783

TSS3005 opened this issue May 12, 2023 · 0 comments

Comments

@TSS3005
Copy link

TSS3005 commented May 12, 2023

Hi,

I tried to call a stored procedure like in your example but it doesn't work.
Here is what I did on the SQL server:

SELECT @@version;

Microsoft SQL Server 2019 (RTM-CU18) (KB5017593) - 15.0.4261.1 (X64) 	
Sep 12 2022 15:07:06 	Copyright (C) 2019 Microsoft Corporation	
Developer Edition (64-bit) on Linux (Oracle Linux Server 8.7) <X64>


CREATE TABLE accounts1 (
    id INT,
    account varchar(100)
);

INSERT INTO accounts1 (
    id,
    account
)
VALUES(
    122,
    'Miller'
    ),
    (
    123,
    'Smith'    
    ),
    (
    124,
    'Johnson'    
    );   

CREATE OR ALTER PROCEDURE [dbo].[sp_RunMe](@ID INT, @Account VARCHAR(100) OUTPUT)
AS
BEGIN
    SET NOCOUNT ON;
    SELECT account FROM accounts1 WHERE id = @ID
END;

Here is my go code:

func main() {
	
	connectionString := fmt.Sprintf("user id=%s;password=%s;port=%s;database=%s", user, password, port, database)
	db, err := sql.Open("mssql", connectionString)
	if err != nil {
		fmt.Println(fmt.Errorf("error opening database: %v", err))
	}
	defer db.Close()
	err = db.Ping()
	if err != nil {
		fmt.Println("Could not ping database!")
	}
	fmt.Println("Database was pinged")

	var account = "abc"
	_, err = db.ExecContext(ctx, "sp_RunMe",
		sql.Named("ID", 123),
		sql.Named("Account", sql.Out{Dest: &account}),
	)
	fmt.Println(account)

If I try to run this I get this:

[tss@localhost mssql1]$ ./mssql1
Database was pinged
abc

Is the Linux version of the SQL server not supported or am I doing something wrong?
I'm grateful for every helpful hint.

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant