问题标签 [dbcommand]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
814 浏览

c# - 使用 Newtonsoft.Json 序列化 DbCommand

我正在尝试将实体框架序列化为DbCommandjson Newtonsoft.Json

但是,在结果 json 文件中,参数是ToString()值而不是对象:

如何告诉序列化程序序列化整个对象?

0 投票
2 回答
2962 浏览

c# - 无法在实体框架的 DbCommand 中传递参数

当我尝试使用 DbCommand 将参数传递给存储过程时出现错误

返回错误:

过程或函数“Procedure_Name”需要未提供的参数“@TEID”。

这些是我的程序参数:

我执行过程和传递参数的代码:

我试图删除@标志并发送SqlParameter而不是DbParameter但我仍然有同样的问题。

在我的存储过程非常复杂并且包含多集的情况下,有没有其他方法可以做到这一点

谢谢...

0 投票
3 回答
2641 浏览

c# - Performing multiple inserts at once in oracle with ExecuteNonQuery

I'm trying to execute multiple inserts at once like this

but i got Oracle.ManagedDataAccess.Client.OracleException: 'ORA-00911: invalid character' even I can manually execute the generated query from sqldeveloper with no issues.

I alreay did this in the past with sqlserver and sqlite, and i had no issues.

why this happens? is there a cleaner way?


here is the generated sql:

0 投票
0 回答
136 浏览

c# - 超时错误 Sql 异常 0 x 80131904 .Net Core

我正在使用 .NET Core 并试图找出 SQL Server localdb 不工作的原因。我正在使用 Dapper 连接到数据库,并使用断点检查所有数据是否都在那里。尝试ExecuteReader从类中调用方法时出现此错误DbCommand

我的 SQL Server 连接字符串是:

我使用 localdb SQL Server 数据库并尝试使用 SQL Server Management Studio 连接到它,并且成功。我注册用户的代码在这里:

RegisterUser首先调用它将用户的数据插入数据库,受影响的行返回为 1 而不是 0。当我右键单击数据库用户表并单击“查看数据”时,我看不到任何数据。

在插入数据后,调用该RetrieveUserId方法检索 SQL Server 自动生成的用户 ID。该retrieveCmd.ExecuteReader()行是超时发生的地方。我在 SQL 语句中尝试了dbo.前面的前缀,Users它也不起作用。

我还尝试了ExecuteReaderandExecuteNonQuery方法的异步版本,但没有奏效。我迷失了下一步该做什么任何帮助将不胜感激。

0 投票
1 回答
265 浏览

entity-framework - Entity Framework Core 3.1 DbCommandInterceptor 仅记录 SELECT 查询

我已经实现了一个 DbCommandInterceptor,以便我可以记录 EF 生成的查询。

我已在 OnConfiguring 方法中将拦截器添加到我的 EF 上下文中,如下所示

拦截器工作,我可以看到任何生成的 SELECT sql 查询。但是,我没有看到任何 UPDATE、INSERT 或 DELETE 查询被记录。

我的 DBContextInterceptorLogging 类在重写的 ScalarExecuting、NonQueryExecuting、ReaderExecuting、NonQueryExecutingAsync 方法中启动 StopWatch,在 ScalarExecuted、NonQueryExecuted、ReaderExecuted、NonQueryExecutedAsync 方法中停止 StopWatch,并将 DbCommand.CommandText 写入 ILogger<>。

我还覆盖了 CommandCreated、CommandFailed 和 CommandFailedAsync 方法。

但是,我从未在记录器输出中看到 SQL INSERT/UPDATE/DELETE。

如果我无意中设置了一些标志或过滤器?

0 投票
0 回答
19 浏览

sybase - Sybase 冻结多个查询上的 DbCommand.ExecuteScalar()

我正在使用旧的 Sybase 数据库,在一个有Identity列的表上。向表中插入值时,我需要检索新的标识值。

我一直在这里那里收集想法。由于数据库不知道Ident_Current(), nor Scope_Identity, 也不知道Insert查询可以有Output子句,因此我尝试OleDbCommand使用以下内容初始化 an:

当执行到达OleDbCommand.ExecuteScalar()时,它似乎冻结了。(暂停调试表明它仍在该指令上,但它似乎没有做任何事情。)

检查 的内容TableName表明新行已正确插入TableName

但我没有得到任何结果。

我也试过用 替换Select Max(Tbl_Id) From DatabaseName..TableName;Select @@Identity;但这似乎并没有改善这种情况。

我究竟做错了什么?

(或者,我可以在一个事务中分别运行这两个查询,但我也想知道为什么我的解决方案不起作用。)