Re: System.Data.SqlClient.SqlException: Timeout expired. The timeout p

K

Karl Seguin

If you are running a long query, you'll need to set a higher timeout for the
sqlcommand....it defaults to 20 or 30 or something seconds....

Karl
 
Joined
Sep 4, 2007
Messages
1
Reaction score
0
Hi

The following code will connect the sql adapter and sql command, applying this will solve the timeout exception

DbConn.Open()
Dim DbCmd As New SqlClient.SqlDataAdapter
Dim cmd As New SqlCommand(sSQL, DbConn)
cmd.CommandTimeout = 250
DbCmd.SelectCommand = cmd
Dim Dt As New DataTable
DbCmd.Fill(Dt)
DbConn.Close()
Return Dt

Same logic can be applied to oledb command also

Dim DbCmd As New OleDb.OleDbDataAdapter
Dim cmd As New OleDb.OleDbCommand(sSQL, OraConn)
cmd.CommandTimeout = 250
DbCmd.SelectCommand = cmd
Dim Dt As New DataTable
DbCmd.Fill(Dt)
DbConn.Close()
Return Dt

Happy Programming
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,006
Latest member
LauraSkx64

Latest Threads

Top