I have a Windows Forms app written in C#, and part of the app has a Reporting form using RDLC reports and a ReportViewer control.
我有一个用C#编写的Windows窗体应用程序,部分应用程序有一个使用RDLC报告和ReportViewer控件的报告表单。
In order to create the reports, for each report I first created a DataSet and added a TableAdapter to the DataSet. I used the TableAdapter wizard to specify the query for the report, and I selected a ConnectionString that was already defined in App.Config and is used elsewhere in the application.
为了创建报告,我首先为每个报告创建了一个DataSet,并将一个TableAdapter添加到DataSet中。我使用TableAdapter向导指定报告的查询,并选择了已在App.Config中定义的ConnectionString,并在应用程序的其他位置使用。
Everything works fine on my development box, but when I move the app to production where the database password isn't the same as my dev box, the reports all fail to run with the exception that the 'sa' password is invalid.
在我的开发盒上一切正常,但是当我将应用程序移动到生产时,数据库密码与我的开发框不同,报告都无法运行,但“sa”密码无效。
Now, the password is set properly in the ConnectionString in app.config in production. I use this same ConnectionString everywhere else in the app, including to log in, so I know that the sa password is set properly.
现在,在生产中的app.config中的ConnectionString中正确设置了密码。我在应用程序的其他地方使用相同的ConnectionString,包括登录,所以我知道sa密码设置正确。
It seems to me that when I add a TableAdapter to a DataSet using the wizard, and it asked me to choose a connection (which I chose the existing connection that was already in app.config and is used elsewhere in the app), it must be storing it somewhere and not always reading it from app.config. Or am I misunderstanding something?
在我看来,当我使用向导将DataAdapter添加到DataSet时,它要求我选择一个连接(我选择已经在app.config中的现有连接并在应用程序的其他地方使用),它必须将它存储在某个地方并不总是从app.config中读取它。还是我误解了什么?
I just want each DataSet with its TableAdapter to be able to use the connection string from app.config, which includes the username and password.
我只希望每个DataSet及其TableAdapter能够使用app.config中的连接字符串,其中包括用户名和密码。
Does anyone know how to do that?
有谁知道这是怎么做到的吗?
1 个解决方案
#1
0
I hacked around this by doing the following before calling the Fill method on the TableAdapter...
在调用TableAdapter上的Fill方法之前,我通过执行以下操作来解决这个问题...
this.EMPLOYEETableAdapter.Connection.ConnectionString =
ConfigurationManager.ConnectionStrings["MCLabor"].ToString();
This works. It's kind of lame though, and it definitely proves that when you create the TableAdapter using the wizard, and you select an existing connection from App.Config (from the Connections drop down box in the wizard), it doesn't actually load that connection string from app.config at runtime. Does anyone know why, or what the real way to handle this is? I don't like having to manually set the connection string for every TableAdapter for every DataSet for every report.
这很有效。虽然它有点蹩脚,但它肯定证明当你使用向导创建TableAdapter,并从App.Config中选择现有连接时(从向导的Connections下拉框中),它实际上并没有加载该连接运行时来自app.config的字符串。有谁知道为什么,或者处理这个问题的真正方法是什么?我不喜欢为每个报告的每个DataSet手动设置每个TableAdapter的连接字符串。
#1
0
I hacked around this by doing the following before calling the Fill method on the TableAdapter...
在调用TableAdapter上的Fill方法之前,我通过执行以下操作来解决这个问题...
this.EMPLOYEETableAdapter.Connection.ConnectionString =
ConfigurationManager.ConnectionStrings["MCLabor"].ToString();
This works. It's kind of lame though, and it definitely proves that when you create the TableAdapter using the wizard, and you select an existing connection from App.Config (from the Connections drop down box in the wizard), it doesn't actually load that connection string from app.config at runtime. Does anyone know why, or what the real way to handle this is? I don't like having to manually set the connection string for every TableAdapter for every DataSet for every report.
这很有效。虽然它有点蹩脚,但它肯定证明当你使用向导创建TableAdapter,并从App.Config中选择现有连接时(从向导的Connections下拉框中),它实际上并没有加载该连接运行时来自app.config的字符串。有谁知道为什么,或者处理这个问题的真正方法是什么?我不喜欢为每个报告的每个DataSet手动设置每个TableAdapter的连接字符串。