完成c#中的执行后关闭sqlcmd(Close sqlcmd after finishing executing in c#)
我有多个非常大的sql文件,我试图使用sqlcmd在我的C#代码中自动运行。 我使用ProcessStartInfo来启动命令提示符,然后从那里运行sqlcmd。 但是,一旦sqlcmd完成第一个文件的运行,命令窗口就会保持运行,我的应用程序会挂起“等待退出”。 我怎么做到这样我的命令提示符在执行我的sql文件后退出?
for (int i = 1; i <= fileCount; i++) { string readFile = fileToRead + "_" + i + ".sql"; string writeFile = fileToWrite + "_" + i + ".txt"; string commandString = "sqlcmd -S myservername -d mydatabasename -i " + readFile + " -o " + writeFile + " -a 32767"; ProcessStartInfo ProcessInfo; ProcessInfo = new ProcessStartInfo("cmd.exe", "/K " + commandString); ProcessInfo.CreateNoWindow = true; ProcessInfo.UseShellExecute = false; ProcessInfo.RedirectStandardOutput = true; using (Process Process = Process.Start(ProcessInfo)) { Process.WaitForExit(); //hangs here because window stays open, have to manually exit it to continue } }
I have multiple very large sql files that I'm trying to run automatically in my C# code using sqlcmd. I use ProcessStartInfo to launch the command prompt and from there run sqlcmd. However, once sqlcmd finishes running the first file, the command window stays up and my application hangs at "Wait for Exit". How do I make it so my command prompt exits after executing my sql file?
for (int i = 1; i <= fileCount; i++) { string readFile = fileToRead + "_" + i + ".sql"; string writeFile = fileToWrite + "_" + i + ".txt"; string commandString = "sqlcmd -S myservername -d mydatabasename -i " + readFile + " -o " + writeFile + " -a 32767"; ProcessStartInfo ProcessInfo; ProcessInfo = new ProcessStartInfo("cmd.exe", "/K " + commandString); ProcessInfo.CreateNoWindow = true; ProcessInfo.UseShellExecute = false; ProcessInfo.RedirectStandardOutput = true; using (Process Process = Process.Start(ProcessInfo)) { Process.WaitForExit(); //hangs here because window stays open, have to manually exit it to continue } }
原文:https://stackoverflow.com/questions/40411855
最满意答案
没有验证规则定义
从问题中,比较:
'request_alliance' => array( 'required' => true, 'allowEmpty' => false ),
同
'type' => array( 'required' => true, 'allowEmpty' => false, 'rule' => array('between', 1, 2) )
在第一种情况下没有规则,如果将验证规则定义为数组,则规则是必需键。
使用notEmpty验证规则
从定义的验证规则来看,似乎存在误解。 您可能需要notEmpty验证规则:
'request_alliance' => array( 'rule' => 'notEmpty' )
如果要确保所有保存中都存在该字段,请使用所需的密钥
'request_alliance' => array( 'rule' => 'notEmpty', 'required' => true )
无需定义allowEmpty键 ,因为如果为false,则与notEmpty验证规则相同,如果定义为true,则与notEical相同。
There is no validation rule definition
From the question, compare:
'request_alliance' => array( 'required' => true, 'allowEmpty' => false ),
With
'type' => array( 'required' => true, 'allowEmpty' => false, 'rule' => array('between', 1, 2) )
In the first case there is no rule, rule is a mandatory key if you define the validation rules as an array.
Use the notEmpty validation rule
From the validation rules defined, it looks like there's a misunderstanding. You probably want the notEmpty validation rule:
'request_alliance' => array( 'rule' => 'notEmpty' )
If you want to ensure that the field is present in all saves, use the required key
'request_alliance' => array( 'rule' => 'notEmpty', 'required' => true )
There is no need to define the allowEmpty key, as it is the same as the notEmpty validation rule if false, and illogical if defined as true.
相关问答
更多-
LINUX 如何查看JPG文件[2022-06-13]
find -
问题是您尝试使用的规则未在CakePHP框架中定义。 如果你想要一些东西并确保该字段不是空的,你应该试试这个: 'title' => array( 'required' => array( 'rule' => array('minLength', 1), 'allowEmpty' => false, 'message' => 'Please enter a title.' ...
-
@ndm非常感谢您的所有提示! 你是对的! 通过这个电话 $client = $this->Clients->patchEntity($client, $this->request->data); 数据经过验证,只有在验证结果为肯定的情况下才会设置。 将$logo设置为请求中的值,清除了验证状态,因此未在屏幕上显示。 我已经评论过了 if (!empty($this->request->data) && !empty($this->request->data['logo']) && !empty($this ...
-
您必须制定一个自定义验证规则 。 在你的模型中添加这个: public function isUniqueOrInList(array $data, array $list) { return in_array(current($data), $list) || $this->isUnique($data); } 然后声明你的规则: 'rule' => array('isUniqueOrInList', array('111213', '141516', '171819', '202122')) ...
-
杰里米哈里斯在这次讨论中帮助了我。 在CakePHP 2.x上, required属性必须与规则一起使用; 但在规则之外,它将被确定为一个单独的规则。 jeremyharris on this discuss helped me. On CakePHP 2.x the required attribute must be used with a rule; But outside of a rule it will be determined as a separated rule.
-
我解决了问题..是模型的名称,并没有认可验证 I solved the problem.. was the name of the model and doesnt recongnize the validation
-
没有验证规则定义 从问题中,比较: 'request_alliance' => array( 'required' => true, 'allowEmpty' => false ), 同 'type' => array( 'required' => true, 'allowEmpty' => false, 'rule' => array('between', 1, 2) ) 在第一种情况下没有规则,如果将验证规则定义为数组,则规则是必需键。 使用notEmp ...
-
您可以导入该类并在框架中的任何位置使用它,如下所示: App::import('Component', 'RequestHandler'); // import class $requestHandler = new RequestHandlerComponent(); // instantiate class $isMobile = $requestHandler->isMobile(); // call method var_dump($isMobile); // output: bool(true) ...
-
cakePHP验证(cakePHP validation)[2023-10-12]
您的问题在于规则语法: array('maxLength' => 80) 就像你的其他规则一样,它不是=> : array('maxLength', 80) 。 顺便说一句,我的城市可以那么长: http : //en.wikipedia.org/wiki/Krung Thep Mahanakhon Amon Rattanakosin Mahinthara ...... ;-) Your problem is in the rule syntax: array('maxLength' => 80) Ju ... -
我在cakephp官方网站上找到了答案: if ($this->ModelName->saveAll( $this->request->data, array('validate' => 'only') )) { // validates } else { // does not validate } 我用上面的代码替换了$this->Post->Validates()来验证多个模型 I found the answer on cakephp official site: if ( ...