简体   繁体   English

C#ASP.NET for SQL的连接字符串

[英]Connection string for C# ASP.NET for SQL

I was wondering if are you able to have two connection strings for two different databases from one SQL Server in one page, for ASP.NET, using C# and Visual Studio. 我想知道您是否能够使用C#和Visual Studio在一页中为一个ASP.NET从一个SQL Server中为两个不同的数据库提供两个连接字符串。

Any advise would be helpful, thank you! 任何建议都会有所帮助,谢谢!

yes, is the answer of course you can. 是的,当然可以。 Just put both connection strings in the respective config files and switch on them as appropriate. 只需将两个连接字符串放入相应的配置文件中,然后根据需要打开它们。 If i was you i would perhaps write some kind of helper class that just allows you to pass in the connection string name. 如果我是你,我可能会写某种帮助程序类,只允许您传入连接字符串名称。 Or you could just use the standard ConfigurationManager API to interact with the config files that way. 或者,您可以只使用标准的ConfigurationManager API来与配置文件进行交互。

But without anything more specific in terms of code samples that's about all the advice i can offer up. 但是在代码示例方面没有任何更具体的内容,这是我可以提供的所有建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM