两个连接字符串 [英] two connection string

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

问题描述

大家好,我已经创建了一个小型Windows应用程序,我的应用程序包含2个连接字符串
如果第一个连接可用,它将连接到该数据库并保存数据,否则它将连接到第二个连接字符串并保存数据,
就我而言,如果我的第一个连接失败,那么花很长时间返回并读取我的第二个连接字符串

如何解决此问题

hi all i have created small windows application,my application contains 2 connection string
if the 1 st connection available it will connect to that database and save the data,else it will connect to the 2nd connect string and save the data,
in my case, if my 1st connection fails, it taking too long time to come back and read my 2nd connection string

how to solve this issue

推荐答案

您可以指定 ^ ]属性,它是等待连接打开的时间.

默认值为15秒,因此您可能需要更改它

在此处查看示例

http://msdn.microsoft. com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring%28v = vs.71%29.aspx [
You can specify a Connection Timeout [^]property, which is the amount of time to wait for connection to open.

The default is 15 seconds, so you may want to change that for your needs

See examples here

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring%28v=vs.71%29.aspx[^]


[C#]
public void CreateSqlConnection()
 {
    SqlConnection myConnection = new SqlConnection();
    myConnection.ConnectionString = "Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=mySQLServer;Connect Timeout=30";
    myConnection.Open();
 }


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

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