如何使用C#中的一个数据库连接连接多个用户名和密码? [英] How to connect with multiple username and password with one database connection in C#?

查看:186
本文介绍了如何使用C#中的一个数据库连接连接多个用户名和密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我当前的开发环境中,他们希望将SQL Server的用户名和密码更改为新的,但需要在删除或禁用之前至少保留旧的SQL Server。但与此同时,两个连接都需要同时使用,如果一个失败然后尝试另一个!



所以,请任何想法或帮助实现这一目标?



谢谢,

In my current development environment they would like to change the username and password of SQL Server to new one but need to keep the old one at least 1 month before delete or disable it. But at the meantime both connection are need to use at the same time if one failed then try another!

So, please any idea or help on this to achieve this goal?

Thanks,

推荐答案

首先尝试使用一个凭据。如果连接失败,则捕获特定的SQL异常。在catch块中,使用单独的凭证调用另一个/相同的方法。将凭证作为参数传递。我们尝试过这种方式,它对我们有用。
First try with one credentials. Catch specific SQL exception if failed to connect. Inside catch block call another/same method with a separate credential. pass credential as a parameter. We have tried this way and it worked for us.


这篇关于如何使用C#中的一个数据库连接连接多个用户名和密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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