R
rsherman
I am running a windows app. with a stored procedure and
the stored proc runs up to 90 seconds, the time out in
the connection string is set for 90 seconds. It seems
that the time out setting is ignored no matter what I set
it to. I have tried all different objects e.g.
datatables,etc... and all providers
(OLDEDB,ODBC,SLQCLIENT) If the SP runs under 30 seconds
the app works, else it returns:
System.Data.SqlClient.SqlException: Timeout expired. The
timeout period elapsed prior to completion of the
operation or the server
This is all the code!!
Option Strict On
Imports System.Data
Imports System.Data.SqlClient
Imports System.Diagnostics
Imports System.Configuration
Imports System.Data.Odbc
Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
Dim sConn As String
sConn = "user id=sa;pwd=pass;database=sample;
server=sample; Connect Timeout=90;"
Dim sStart As String = txtStartDate.Text.Trim
Dim sEnd As String = txtEndDate.Text.Trim
Dim sStore As String = txtStore.Text.Trim
Dim conn As New SqlConnection(sConn)
Dim cmd As New SqlCommand("gp_LasikCommissions_1", conn)
cmd.CommandType = CommandType.StoredProcedure
conn.Open()
Dim Param As New SqlParameter("@StartDate",
SqlDbType.DateTime)
Param.Direction = ParameterDirection.Input
Param.Value = sStart
cmd.Parameters.Add(Param)
Dim Param1 As New SqlParameter("@EndDate",
SqlDbType.DateTime)
Param1.Direction = ParameterDirection.Input
Param1.Value = sEnd
cmd.Parameters.Add(Param1)
Dim Param2 As New SqlParameter("@Store_No",
SqlDbType.Char)
Param2.Direction = ParameterDirection.Input
Param2.Value = sStore
cmd.Parameters.Add(Param2)
Dim myReader As SqlDataReader
Try
myReader = cmd.ExecuteReader()
Catch ex As Exception
Console.WriteLine(ex.ToString)
End Try
Try
While myReader.Read()
Console.WriteLine((myReader(0).ToString & ", " & myReader
(1).ToString & ", " & myReader(2).ToString))
End While
Catch ex As NullReferenceException
Console.WriteLine(ex.ToString)
Finally
' always call Close when done reading.
If Not myReader Is Nothing Then
myReader.Close()
End If
' always call Close when done reading.
conn.Close()
End Try
End Sub
End Class
the stored proc runs up to 90 seconds, the time out in
the connection string is set for 90 seconds. It seems
that the time out setting is ignored no matter what I set
it to. I have tried all different objects e.g.
datatables,etc... and all providers
(OLDEDB,ODBC,SLQCLIENT) If the SP runs under 30 seconds
the app works, else it returns:
System.Data.SqlClient.SqlException: Timeout expired. The
timeout period elapsed prior to completion of the
operation or the server
This is all the code!!
Option Strict On
Imports System.Data
Imports System.Data.SqlClient
Imports System.Diagnostics
Imports System.Configuration
Imports System.Data.Odbc
Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
Dim sConn As String
sConn = "user id=sa;pwd=pass;database=sample;
server=sample; Connect Timeout=90;"
Dim sStart As String = txtStartDate.Text.Trim
Dim sEnd As String = txtEndDate.Text.Trim
Dim sStore As String = txtStore.Text.Trim
Dim conn As New SqlConnection(sConn)
Dim cmd As New SqlCommand("gp_LasikCommissions_1", conn)
cmd.CommandType = CommandType.StoredProcedure
conn.Open()
Dim Param As New SqlParameter("@StartDate",
SqlDbType.DateTime)
Param.Direction = ParameterDirection.Input
Param.Value = sStart
cmd.Parameters.Add(Param)
Dim Param1 As New SqlParameter("@EndDate",
SqlDbType.DateTime)
Param1.Direction = ParameterDirection.Input
Param1.Value = sEnd
cmd.Parameters.Add(Param1)
Dim Param2 As New SqlParameter("@Store_No",
SqlDbType.Char)
Param2.Direction = ParameterDirection.Input
Param2.Value = sStore
cmd.Parameters.Add(Param2)
Dim myReader As SqlDataReader
Try
myReader = cmd.ExecuteReader()
Catch ex As Exception
Console.WriteLine(ex.ToString)
End Try
Try
While myReader.Read()
Console.WriteLine((myReader(0).ToString & ", " & myReader
(1).ToString & ", " & myReader(2).ToString))
End While
Catch ex As NullReferenceException
Console.WriteLine(ex.ToString)
Finally
' always call Close when done reading.
If Not myReader Is Nothing Then
myReader.Close()
End If
' always call Close when done reading.
conn.Close()
End Try
End Sub
End Class