使用连接字符串连接到多个主机 [英] Connecting to multiple hosts using connection string

查看:87
本文介绍了使用连接字符串连接到多个主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要连接到具有不同主机的数据库服务器.我将通过遍历一些数据来频繁更改主机.如何使连接字符串动态化,以便可以在需要时更改主机名.

此外,连接字符串中的用户名和密码在所有主机中都相同.我需要对连接字符串中的用户名和密码进行加密.

I need to connet to database server with different hosts. I will change the host frequently by iteretaing through some data. How can i make the connection string dynamic so that i can change the host name whenever I need.

Also the username and password in the connection string is same throughout all hosts.I need to encrypt the username and password in the connection string. Please guide in this too.

推荐答案

连接字符串只是一个字符串.更改连接字符串中的服务器名称是非常简单的字符串操作.我建议只在连接字符串中放置一个已知标记来代替实际的服务器名称.当您想更改服务器名称时,这是对字符串上的Replace方法的非常简单的调用,以将已知标签替换为服务器名称.

至于加密用户名和密码,您不需要.您可以对app.config文件中的整个连接字符串进行加密.阅读 [
The connection string is just a string. It''s very simple string manipulation to change the server name in a connection string. I would suggest just putting a known tag in the connection string in place of an actual server name. When you want to change the server name, it''s a very simple call to the Replace method on the string to replace the known tag with the server name.

As for encrypting the username and password, you don''t. You encrypt the entire connection string in your app.config file. Read this[^].


这篇关于使用连接字符串连接到多个主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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