Avatar of kgittinger
kgittingerFlag for United States of America

asked on 

How to add timeout to connection string

Where should the timeout seconds be entered in the connection string for exequeting a query on the below connection?  I need 120 seconds...

    Dim cn As OleDbConnection
    Const strCN As String = "Provider=SQLNCLI10.1;Integrated Security=SSPI;Persist Security Info=False;User ID='';Initial Catalog=MyTable;Data Source=BS-120471\SQLEXPRESS;Initial File Name='';Server SPN=''"
Visual Basic ClassicVB Script

Avatar of undefined
Last Comment
brutaldev
ASKER CERTIFIED SOLUTION
Avatar of brutaldev
brutaldev
Flag of South Africa image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of kgittinger
kgittinger
Flag of United States of America image

ASKER

Is there any chance you could provide an example of this connection builder at work?  I am unsure about adding the "connections timeout"

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Sample.mdb;User ID="Admin;NewValue=Bad"

THanks!
Avatar of brutaldev
brutaldev
Flag of South Africa image

You can simply change your connection string to:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Sample.mdb;User ID=Admin;NewValue=Bad;Connect Timeout=600
The default is 15 seconds (the example sets it to 10 mins). You can set it to zero to be unlimited but of course this is not not recommended.

What I meant by using the builder is for a SQL Server connection string, you can load your string in and then change it via easy to see properties. EG:
 
Dim builder As New SqlConnectionStringBuilder("Provider=SQLNCLI10.1;Integrated Security=SSPI;Persist Security Info=False;User ID='';Initial Catalog=MyTable;Data Source=BS-120471\SQLEXPRESS;Initial File Name='';Server SPN=''")
builder.ConnectTimeout = 600
' Set more properties here.

Using conn As New SqlConnection(builder.ToString())
	conn.Open()
...
End Using

Open in new window

.ToString() it when you're done to get the connection string it represents. Unfortunately the OleDbConnectionStringBuilder does not have the properties as nicely defined.
Visual Basic Classic
Visual Basic Classic

Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.

165K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo