查找参数化查询的 SQL 输出
我正在使用 C# 对 SQL Server 2005 实例进行参数化查询,并且我想查看针对数据库运行的 SQL 以进行调试。我可以在数据库日志或 Visual Studio 调试器中查看参数化命令的输出 SQL 是什么吗?
I'm making a parameterized query using C# against a SQL server 2005 instance, and I'd like to take a look at the SQL that is run against the database for debugging purposes. Is there somewhere I can look to see what the output SQL of the parameterized command is, either in the database logs or in the Visual Studio debugger?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 SQL Server Profiler 查看 SQL
http://www.eggheadcafe.com/articles/sql_server_profiler。 asp
http://msdn.microsoft.asp com/en-us/library/ms187929(SQL.105).aspx
Use SQL Server Profiler to view the sql
http://www.eggheadcafe.com/articles/sql_server_profiler.asp
http://msdn.microsoft.com/en-us/library/ms187929(SQL.105).aspx
SQL Profiler 是最好的解决方案,但如果您的应用程序需要一些更有机的东西,您可以在生产、QA 等中部署和启用/禁用...那么您可以围绕 System.Data.SqlClient Provider 构建一个包装器(< em>例如,在配置文件中注册的提供程序为...providerName="System.Data.SqlClient")。
这本质上就像一个拦截代理,它可以让您访问通过提供者(例如在您的应用程序和数据库客户端之间)传递的所有信息。这将使您能够吸取、拦截、修改、聚合和/或丰富您需要的内容。这是更先进的一点,但为捕获整个范围的信息打开了大门,并且可以作为单独的关注层插入/替换/删除。
SQL Profiler is the best solution, but if you need something more organic to your application that you could deploy and enable/disable in production, QA, etc... then you could build a wrapper around the System.Data.SqlClient Provider (Ex. the provider registered in the config file as... providerName="System.Data.SqlClient").
This would essentially act like an intercept proxy which would give you access to all the information passing through the Provider (e.g. between your application and the database client). This would allow you to siphon-off what you need, intercept, modify, aggregate and/or enrich it. This is a bit more advanced but opens the door to capture a whole range of information and could be inserted/replaced/removed as a separate layer of concern.