Why do I have TimeOut

  • Thread starter Thread starter Marc Robitaille
  • Start date Start date
M

Marc Robitaille

Hello,

In my Global.asax, I have my connection string
Application("strDSNSQL") = "SERVER=(local); UID=LOGIVELO_USER;
PWD=!ItsAll4Me; DATABASE=Logivelo1"

I have thise code in an ASPX page

Dim DecisionCompagnie As Compagnie

Dim dtDecisionCompagnie As DataTable

DecisionCompagnie = New Compagnie()

dtDecisionCompagnie =
DecisionCompagnie.GetLastDecision(Session("compagnie"), Session("Periode"),
Application("strDSNSQL"))

If dtDecisionCompagnie.Rows.Count > 0 Then
txtNomCompagnie.Text = dtDecisionCompagnie.Rows(0).Item(4)
txtNomGroupe.Text = dtDecisionCompagnie.Rows(0).Item(2)
txtPeriode.Text = Session("Periode")
txtEmissionAction.Text = dtDecisionCompagnie.Rows(0).Item(6)
txtEmpruntLongTerme.Text = dtDecisionCompagnie.Rows(0).Item(7)
txtRemboursement.Text = dtDecisionCompagnie.Rows(0).Item(9)
....
This is the function that I call in my Compagnie Class

Public Function GetLastDecision(ByVal pstrId As String, ByVal pintNoPeriode
As Integer, ByVal pstrDSN As String) As DataTable
Dim strCommande As String = ""
Try
strCommande = "SELECT * FROM DecisionCompagnie WHERE NoCompagnie = " &
pstrId & " AND NoPeriode = " & pintNoPeriode
Dim daDataAdapter As New SqlDataAdapter(strCommande, pstrDSN)
Dim dsDataSet As New DataSet()
daDataAdapter.Fill(dsDataSet, "DecisionCompagnie")
Dim dtDataTable As DataTable = dsDataSet.Tables(0)
GetLastDecision = dtDataTable
dtDataTable = Nothing
daDataAdapter = Nothing
Catch...

When I try this code 10 times, 8 times it is ok and 2 times I have a
TimeOut. I have SQLServer 2000 on my computer and I am alone on the
network. I want to understand what I do wrong

Thank you
Marc
 
Is it a connection timeout or a command timeout? Either way, you can use
Profiler to find out what's going on behind the scenes. Are a lot of people
banging on the server or is this just a test machine? Can you open and
close all the other connections in a realistic amount of time? Is it
consistently 8 and 2 and is there any pattern like always the last two
attempts timeout or is it totally random?



A few general points though (not the problem at hand, but something you may
want to conisder)..particularly if this thing will be running on the web,
I'd highly recommend using Stored Procedures instead of dynamic SQL and at a
minimum use parameters for your select statement:

Strings are immutable, so no real need to set it to "" first, you can just
set it in the assignment.
strCommande = "SELECT * FROM DecisionCompagnie WHERE NoCompagnie =
@NoCompagnie > AND NoPeriode = @NoPeriod"

then, with your command object
myCommand.Parameters.Add("@NoCompagnie", SqlDbType.Varchar).Value = pstrId
myCommand.Parameters.Add("@NoPeriod", SqlDbType.Int).Value =
CType(pintNoPeriode, Integer)
'The actual DB Types should map to the read column types, and there are
other overloads for using parameters, but this is just a basic example.
 
You may be running out of SQL connections in the pool.
Instead of setting daDataAdapter to nothing, do a daDataAdapter.Dispose()
(setting the daDataAdapter to nothing does not release the connection).
 
Back
Top