フィルターのクリア

Error running datainsert to insert row in sqlserver database

8 ビュー (過去 30 日間)
Basem Nabil
Basem Nabil 2019 年 5 月 12 日
回答済み: Piyush Kumar 2024 年 7 月 26 日
Hello,
I'm trying to insert a row into my sql server database using datainsert but I keep getting errors everytime I run.
Annotation 2019-05-13 003654.png
I know my connection is correct as it works in fetching data.
conn = database('SqlServer','','');
data = {1 'Deposit' 500};
columns = {'CardID' 'Type' 'Amount'};
table = 'HakunaMatata.dbo.Transcations';
datainsert(conn,table,columns ,data);
close(conn);

回答 (1 件)

Piyush Kumar
Piyush Kumar 2024 年 7 月 26 日
The error you’re encountering with the datainsert function in MATLAB when inserting a row into a SQL Server database might be related to transaction handling.
Here are some steps to troubleshoot and resolve the issue:
  1. Check Transaction Statements: Ensure that your code includes proper BEGIN TRANSACTION and COMMIT TRANSACTION statements. The error indicates a ROLLBACK without a corresponding BEGIN.
  2. Try sqlwrite function instead of datainsert
  3. Verify Data Types: Ensure that the data types of the columns in your MATLAB table match those in the SQL Server table.
  4. Check this link - ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION error in sql server - Stack Overflow. The error statement is similar here.

カテゴリ

Help Center および File ExchangeDatabase Toolbox についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by