发送方式Ado.net连接收缩命令到Microsoft SQL数据库文件 [英] Send shrink Command to Microsoft SQL Database file via Ado.net connection
问题描述
这怎么可能执行直接的SQL命令到ADO.NET连接数据库?
我想一个大的删除处理后发送一个 DBCC SHRINKDATABASE
到SQL服务器,以COM preSS当前的数据文件。 DBCC命令后的功能的ObjectContext ::的createQuery
返回分析器错误。是否有任何其他的方式来收缩数据库文件,或者另一种方式直接发送SQL命令到SQL Server?
How is it possible to execute a direct SQL command to an ADO.NET connected database?
I want to send a DBCC SHRINKDATABASE
to the SQL server, to compress the current datafile after a big deletion process. The function ObjectContext::CreateQuery
returns a parser error after the DBCC command. Is there any other way to shrink the database file, or another way to send the SQL command directly to the SQL Server?
推荐答案
我刚刚发送此为原始的SQL:
I'd just send this as raw SQL:
using (SqlCommand command = new SqlCommand("DBCC SHRINKDATABASE(0)", connection))
{
command.ExecuteNonQuery();
}
另一种方法是把 DBCC SHRINKDATABASE
在存储过程中,并从code调用存储过程。
Another way is to put the DBCC SHRINKDATABASE
in a stored procedure and call the stored procedure from your code.
这篇关于发送方式Ado.net连接收缩命令到Microsoft SQL数据库文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!