如何将配置文件传递给bat文件中的exe文件?

问题描述:

我已经test.exe(控制台应用程序/ Windows应用程序)和test.exe.config在我的机器上的同一目录。如何将配置文件传递给bat文件中的exe文件?

当我打开DOS提示符时,我能够运行test.exe %1 %2 %3,它成功地将数据插入到MS SQL表中。

的test.exe.config从app.config中编译,其中包含此:

<connectionStrings> 
<add name="Common Instance" connectionString="data source=eeeeee;Integrated Security=SSPI;Initial Catalog=YYYY;User ID=xxx;Password=xxxx" providerName="System.Data.SqlClient"/> 
</connectionStrings> 

但是当我运行包含此代码一个bat文件:

START C:\aa\test.exe %1 %2 %3

我得到这个错误信息:

Description: The process was terminated due to an unhandled exception. 
Exception Info: System.Data.SqlClient.SqlException 
Stack: 
    at Microsoft.Practices.EnterpriseLibrary.Data.Database.GetNewOpenConnection() 

我把一个跟踪数据库,一个d当我运行bat文件时,它甚至没有命中。

看来,当我运行bat文件时,它无法找到数据库连接。

我想:

START C:\aa\test.exe %1 %2 %3 "test.exe.config"

START C:\aa\test.exe %1 %2 %3 /config:test.exe.config

START C:\aa\test.exe %1 %2 %3 /config:App.config

他们都没有工作。我会欣赏一些指针。

我的猜测是工作目录需要在批处理文件中设置。这就是为什么它找不到.config文件。将工作目录设置为应用程序和文件所在的文件夹。

cd C:\aa 
start test.exe %1 %2 %3 
+0

感谢您的建议。它没有解决我的问题。 – user2142250 2013-03-07 20:18:29