没有断点,Datediff不起作用 [英] Datediff doesnt work without breakpoint

查看:91
本文介绍了没有断点,Datediff不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.
我有两个数据库,分别在客户端和服务器上.每次我在客户端数据库中添加某些内容时,我都希望在服务器中对其进行更新,因此我运行Sql tablediff.exe.

Hello.
I have two databases, in client and server. Each time im adding something in client database, i want to update it in server, so im running Sql tablediff.exe.

for (int i = 0; i < diffList.Count; i++)
         {

             var proc = new Process()
             {
                 StartInfo = new ProcessStartInfo
                 {
                     FileName = "tablediff.exe",
                     Arguments = "here is all arguments",
                     UseShellExecute = false,
                     RedirectStandardOutput = true,
                     CreateNoWindow = true,

                 }

             };

             proc.Start();

         }


很好创建包含查询的i文件.现在,我想从所有* .sql文件中读取文本并使用sqlcommand执行它们-出现了问题.当我这样尝试时(只是运行代码,没有断点等):



That works fine. Creating i-files, which contains queries. Now i want to read text from all that *.sql files and using sqlcommand execute them - and there is problem. When im trying like that (just running code, no breakpoints etc):


for (int i = 0; i < 11; i++)
                 {
                     try
                     {
                         string text = System.IO.File.ReadAllText("diff"+i+".sql");
     
                         SqlConnection conn = new SqlConnection(cString.connString());
                         using (conn)
                         {
                             conn.Open();
                             SqlCommand cmd = new SqlCommand(text, conn);
                             cmd.ExecuteNonQuery();
                         }
     
                     }
                     catch { MessageBox.Show("No file diff" + i); }
                 }




它不起作用.但是....当我将breakpoin放在conn.Open();行中时,一切都很好...我没有想法要处理它.有人可以帮忙吗? ;)




It doesnt work. BUT.... When i put breakpoin in line conn.Open();, everything works just fine... I have no ide hwo to handle it. Can anyone help? ;)

推荐答案

您的using语句在循环内的问题.


The problem with your using statement as it inside a loop.


for (int i = 0; i < 11; i++)
                 {
                     try
                     {
                         string text = System.IO.File.ReadAllText("diff"+i+".sql");
     
                         using(SqlConnection conn = new SqlConnection(cString.connString()))
                         {
                             conn.Open();
                             SqlCommand cmd = new SqlCommand(text, conn);
                             cmd.ExecuteNonQuery();
                         }
     
                     }
                     catch { MessageBox.Show("No file diff" + i); }
                 }


这篇关于没有断点,Datediff不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆