C# 如何更改 DataSet.xsd 中的连接字符串?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2234938/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change connection string in DataSet.xsd?
提问by Gold
I have build my project in C#, I add DataSet.xsd
, and connect him to
我已经用 C# 构建了我的项目,我添加了DataSet.xsd
,并将他连接到
Oracle DataBase in my computer - work Excellent !!!!
我的计算机中的 Oracle 数据库 - 工作出色!!!!
When I installed on the customer computer (that connect to his Oracle DataBase) -
当我安装在客户计算机上时(连接到他的 Oracle 数据库)-
it crushed.
它压碎了。
I need to change the connection string on the DataSet.xsd
file - but how to do it ?
我需要更改DataSet.xsd
文件上的连接字符串- 但怎么做?
Is there any xml file ? Or configuration file ?
有没有xml文件?还是配置文件?
Thanks in advance.
提前致谢。
采纳答案by Henk Holterman
When generating a DataSet with the Wizard you are asked to Create-and-Store a ConnectionString. Take a look in your App.Config
使用向导生成数据集时,系统会要求您创建并存储 ConnectionString。看看你的 App.Config
回答by Qwerty.ie
You can also open the Dataset and select the TableAdapter that you want to update, right click and go to properties.
您还可以打开数据集并选择要更新的 TableAdapter,右键单击并转到属性。
here you will see a "connection" property that you can easily change to settings in your web.config file or enter new connection details.
在这里,您将看到一个“连接”属性,您可以轻松地将其更改为 web.config 文件中的设置或输入新的连接详细信息。
回答by peter
I had similar situation... I'd already created lots of datasets, and they each recorded their own connection string in the code behind. A also manually interacted with database via connectionstring I'd placed in App.config file. So to update all this when deploying to as-yet-unknown server would be pain; yet manually changing all those connectionstrings also put me off. In the end I added a 'test' tableAdapter to the .xsd design page... and created a New connection string - this time specifying it be placed in App.config file. Then by magic... all the tableAdapters now used this one connectionstring - just delete the test object & voila!
我有类似的情况...我已经创建了很多数据集,并且每个数据集都在后面的代码中记录了自己的连接字符串。还通过我放置在 App.config 文件中的连接字符串手动与数据库交互。因此,在部署到未知服务器时更新所有这些会很痛苦;但是手动更改所有这些连接字符串也让我失望。最后,我在 .xsd 设计页面中添加了一个“测试”tableAdapter...并创建了一个新的连接字符串 - 这次指定将其放置在 App.config 文件中。然后神奇地......现在所有的 tableAdapters 都使用了这个连接字符串 - 只需删除测试对象 & 瞧!
回答by V? V?n Qu?nh
You can using like my code: Note that DataSet can change connection string by app.config but you can change connection string by TableAdapter like below:
您可以像我的代码一样使用:请注意,DataSet 可以通过 app.config 更改连接字符串,但您可以通过 TableAdapter 更改连接字符串,如下所示:
NCKHSV_TTD54TableAdapters.adtReportGiangVienTableAdapter tableAdapter = new
NCKHSV_TTD54TableAdapters.adtReportGiangVienTableAdapter();//Create a TableAdapter to using.
tableAdapter.Connection.ConnectionString = strConn;//change ConnectionString to strConn
tableAdapter.ClearBeforeFill = true;
tableAdapter.Fill(dataset.adtReportGiangVien);
回答by Paulo Santos
Just request server credentials in your application startup once or use a settings window and use this method:
只需在应用程序启动时请求服务器凭据或使用设置窗口并使用此方法:
get the connection string from SqlConnection object or form the connection string from individual data and do it like this:
从 SqlConnection 对象获取连接字符串或从单个数据形成连接字符串,然后像这样执行:
[ApplicationNamespace].Properties.Settings.Default["ConnectionString"] = newconstr;
The application settings that are Application and not user scope can be set too. But only programatically, by code. It works fine for me. Hope it helps you out!
也可以设置应用程序而不是用户范围的应用程序设置。但只能以编程方式,通过代码。这对我来说可以。希望能帮到你!
回答by Dot Freelancer
I was searching about way to change the connectionsString
globally, and finally I find a way to do that.
Open dataset.xsd using notepad program and then replace the old connectionstring with the new one
我一直在寻找改变connectionsString
全局的方法,最后我找到了一种方法来做到这一点。使用记事本程序打开 dataset.xsd,然后用新的连接字符串替换旧的连接字符串
<DbSource ConnectionRef="con_string_ar (Web.config)" DbObjectName="con_string_ar.dbo.albums" DbObjectType="Table"..>
回答by Dot Freelancer
The connection string is stored sometimes in application settings (non-web projects: win forms, libraries...). Right click your project > Properties > Settings. You can then change connection string.
连接字符串有时存储在应用程序设置中(非 Web 项目:win 表单、库...)。右键单击您的项目 > 属性 > 设置。然后您可以更改连接字符串。
For best results, you can first open file app.config
(for non-web projects) and modify your connection string. After that, open project settings to "let visual studio discover changes to connection string and update it automatically".
为获得最佳效果,您可以先打开文件app.config
(对于非 Web 项目)并修改连接字符串。之后,打开项目设置以“让 Visual Studio 发现连接字符串的更改并自动更新它”。
回答by Bernabé Tavarez
If your Dataset is created, select the icon below of the columns that you selected to show. It ends with TableAdapter, go to properties. it shows the current connection string, just change it.
如果您的数据集已创建,请选择您选择显示的列下方的图标。它以 TableAdapter 结尾,转到属性。它显示当前的连接字符串,只需更改它。