英文:
Saving PDF file in SQL Server using Golang
问题
我在使用Golang中的存储过程将PDF文件保存到SQL Server数据库时遇到了问题。以下是代码:
tsql := fmt.Sprintf("DECLARE @tmp varbinary(max);"+
"SET @tmp = CAST('%s' as varbinary(max));"+
"EXEC BP_AddCorrespondenceIn @PatientID=1, @ContactName='Test', @Subject='First Test',"+
"@Category='Report', @DocType='PDF', @Content = @tmp", content)
// 执行查询
rows, err := db().Query(tsql)
这里的content是[ ]byte类型。当我运行程序时,查询执行后出现了以下错误:
mssql: '3�Ze� #��!~T��ϔljQ*���f1-~L���^ը;s;���.�)�[P�hjDN��J�.1��W�Zt���xq�\r���ן�)N���=df' 是无效的名称,因为它包含了一个NULL字符或无效的Unicode字符。
谢谢!
英文:
I'm having issue in saving a PDF file in SQL Server database using stored procedure in Golang. Below is the code.
tsql := fmt.Sprintf("DECLARE @tmp varbinary(max);"+
"SET @tmp = CAST('%s' as varbinary(max));"+
"EXEC BP_AddCorrespondenceIn @PatientID=1, @ContactName='Test', @Subject='First Test',"+
"@Category='Report', @DocType='PDF', @Content = @tmp", content)
// Execute query
rows, err := db().Query(tsql)
Here the content is the [ ]byte. When I run the program the query executes and I got the error below:
> mssql: '3�Ze�
#��!~T��ϔljQ*���f1-~L���^ը;s;���.�)�[P�hjDN��J�.1��W�Zt���xq�\r���ן�)N���=df' is an invalid name because it contains a NULL character or an invalid unicode character.
Thank you!
答案1
得分: 0
我通过将存储过程的执行方法更改为_, err := db().Exec(tsql, content)
,以及将varbinary(max)
转换为tmp = CAST(? as varbinary(max))
来解决了这个问题。
英文:
I fixed the problem by changing the stored procedure exec method to _, err := db().Exec(tsql, content) and varbinary(max) conversion to tmp = CAST(? as varbinary(max));
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论