Tips for setting database connection strings

Source: Internet
Author: User

In the past two days, we have developed a winform software that needs to connect to the database of the server. config to configure the database connection string. The default timeout time is 15 seconds (some people say it is 30 seconds, this is not clear, and there is no time to perform special verification ).

When the software is started, a piece of code is written to verify whether the database connection is normal. According to the default timeout, once the database connection fails, the wait time is too long and you want to change the timeout to 5 seconds. However, when I click the SqlConnection instance, I find that ConnectTimeout is a read-only attribute. I am depressed. When I access Baidu, most people are in the App. config, but I just want to modify the timeout value at startup. In other cases, I want to use the default value. What should I do?

Later, I tried to find another class SqlConnectionStringBuilder, which may also be the help provided by online users. Get the ConfigurationManager App. the connection string information in Config is converted to SqlConnectionStringBuilder, and then the Timeout attribute in the SqlConnectionStringBuilder instance is modified, and then an instance is sqlconnected. The parameters of the constructor are the same as those of the SqlConnectionStringBuilder instance. toString (), finally run the program, the effect is coming out, the waiting time is shorter than before, there is no test time, the visual test should be 5 seconds.

Many experts may know this, But Baidu's answers are not satisfactory. Therefore, record and share the answer with others. In addition, you are welcome to add the experts!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.