小编Kev*_*nco的帖子

SqlCommand中的变量在查询批处理中必须是唯一的..但它是?

我正在制作一个Windows服务来收集大量信息,我将它发送给数据库.我知道下面的方法可行,因为我已经在其他表上使用它而没有错误.但我不得不扩展我的DELETE命令以使用两个条件,现在我收到一个错误.

这是我收到的错误:"变量名称'@deletedrive'已经被声明.变量名在查询批处理或存储过程中必须是唯一的."

这是我的代码(结尾省略了因为它只是捕获了我们得到的异常.还忽略了注释行):

private static void ServerSpaceTimerAction(object source, ElapsedEventArgs e, string InstallLocation)
    {
        //StreamWriter RecordServerSpace = new StreamWriter(InstallLocation + "\\Temp\\ServerSpaceTemp.csv");
        try
        {
            ServerSpace GetSpace = new ServerSpace();
            GetConfigurations Configs = new GetConfigurations();
            Configs.GetServers();
            Configs.GetDatabase();

            var connection = new SqlConnection("Data Source=" + Configs.DataSource + "; Initial Catalog=" + Configs.DatabaseCatalog + "; Integrated Security=" + Configs.IntegratedSecurityProtocol);
            connection.Open();

            char[] delim = { ' ', ',' };
            string sInsertServerSpace = "INSERT INTO ServerSpace (date_time, server, region, farm, technology, role, drive, total_space, free_space) VALUES (@dt, …
Run Code Online (Sandbox Code Playgroud)

c# sql windows-services

4
推荐指数
1
解决办法
3559
查看次数

标签 统计

c# ×1

sql ×1

windows-services ×1