Hello. I am having problems with my form web site, for it takes a long time after the submit button is clicked to enter the data into my database. I have run the two stored procedures in query analyzer and they do not take long at all. However, when i use this form on another computer, it seems to work quite fast (Although a debug message appears). By looking at my code, can anyone see any red flags that are causing the process time to be so slow? I would greatly appreciate any help!
Code:
<%@ Page Language="VB" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SQLClient" %>
<script runat="server">
Dim connstr as string = "Server=localhost;UID=User;PWD=Password;Database=Database"
Dim cancel_page as string = "bscireal.aspx"
Sub Page_Load(sender As Object, e As EventArgs)
Dim rightNow as DateTime = DateTime.Now
If day(RightNow) > 25 Then
lbl_error.text = "You are not able to transfer accounts after the 25th of the month. Please try again next month."
cmdInsert.visible=false
else
lbl_error.text = "Welcome to the Account Transfers Page."
Dim sql as string
if not Page.IsPostBack then
sql = "select AccountID + ' - ' + AccountName as accnumber from Accounts order by AccountName"
FillDropDownList(sql,AccNumber)
end if
if not Page.IsPostBack then
sql = "select distinct territoryName from Territories where CloseDate is Null and territoryName not in ('IS 1','IS 2','IS 3','IS 4','IS 5')"
FillDropDownList(sql,Toname)
end if
end if
End Sub
Sub FillDropDownList(sql as string, ddl as DropDownList)
' Create Connection Object, Command Object, Connect to the database
Dim conn as New SQLConnection(connstr)
Dim cmd as New SQLCommand(sql,conn)
conn.open()
' Execute the SQL, Bind the results to the Dropdown List Control
ddl.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection)
ddl.DataBind()
End Sub
Sub InsertData()
Dim conn as SQLConnection
Conn = New SQLConnection(connstr)
Dim Cmd1 as SqlCommand
Cmd1 = New SQLCommand("Insertaccounts",Conn)
'Declare the command type - a stored proc in this case
Cmd1.commandType = CommandType.storedProcedure
'Add the parameters
Cmd1.parameters.add("@AccountID",AccNumber.SelectedItem.Value)
Cmd1.parameters.add("@Explanation",Explanation.text)
dim cmd2 as SqlCommand
Cmd2 = New SQLCommand("UpdateToTerritory",Conn)
'Declare the command type - a stored proc in this case
Cmd2.commandType = CommandType.storedProcedure
Cmd2.parameters.add("@AccountID",AccNumber.SelectedItem.Value)
Cmd2.parameters.add("@ToName",ToName.SelectedItem.Value)
conn.open()
cmd1.ExecuteNonQuery()
cmd2.ExecuteNonQuery()
conn.Close()
Response.redirect(return_page)
end sub
Sub cmdInsert_Click(sender As Object, e As EventArgs)
InsertData()
End Sub
Sub cmdCancel_Click(sender As Object, e As EventArgs)
response.redirect(cancel_page)
End Sub
</script>
<html>
<head>
<title>Account Transfers</title>
<link href="styles.css" type="text/css" rel="stylesheet" />
</head>
<body class="empty" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0">
<form onsubmit="return Validate(this)" action="transfers.aspx?Enter=True" method="POST" runat="server" name="form1">
<table height="100%" cellspacing="0" cellpadding="0" width="100%" border="0">
<tbody>
<tr bgcolor="#000000">
<td valign="top" align="left">
</td>
</tr>
<tr>
<td width="100%" background="gor_white.gif">
<img height="1" src="images/gor_white.gif" width="20" border="NONE" /></td>
</tr>
<tr bgcolor="#002041">
<td valign="top" align="left" width="100%" height="77">
<img height="77" src="images/header.gif" width="960" /></td>
</tr>
<tr>
<td width="100%" background="gor_white.gif">
<img height="1" src="images/gor_white.gif" width="20" border="NONE" /></td>
</tr>
<tr bgcolor="#36647e">
<td valign="top" align="left">
</td>
</tr>
<tr>
<td valign="center" align="middle" height="98%"><br />
<table bordercolor="#5e768e" cellspacing="0" cellpadding="5" width="770" bgcolor="#b6cce4" border="1">
<tbody>
<tr><td colspan="2" align="center" valign="middle"><asp:Label id="lbl_error" runat="server" width="500px" font="verdana" font-bold="True" forecolor="#002041"> </asp:Label></center></td></tr>
<td width="440" border="0" valign="top"><br />
<font face="Verdana" size="2"><b>Account: </b></font><br />
<asp:DropDownList id="AccNumber" name="AccNumber" runat="server" DataValueField="accnumber" DataTextField="AccNumber" Width="440px"></asp:DropDownList>
<br /><br />
<font face="Verdana" size="2"><b>Transfer to:</b></font><br />
<asp:DropDownList id="ToName" name="ToName" runat="server" DataValueField="TerritoryName" DataTextField="TerritoryName" Width="220px"></asp:DropDownList><br /><br /><br /><font face="Verdana" size="2"><b>Explanation:</b></font><br />
<asp:TextBox id="Explanation" TextMode="MultiLine" runat="server" Width="440px" Height="131px"></asp:TextBox><br /><br />
<center>
<asp:Button id="cmdInsert" onclick="cmdInsert_Click" runat="server" Text="Request Transfer" type="submit"></asp:Button>
<asp:Button id="cmdCancel" onclick="cmdCancel_Click" runat="server" Text="Cancel"></asp:Button>
</center>
</td><td width="330">
<CENTER>
</tbody>
</table>
</td>
</tr>
</form>
<td valign="top" align="middle">
</td></tr>
<tr>
<td valign="top" align="middle" colspan="3">
<hr color="#5e768e" />
</td>
</tr>
<tr>
<td valign="top" align="middle" colspan="3" bgcolor="#002041">
<font class="text_bold_bl" color="#FFFFFF" face="verdana" size="1">The contents of this site are highly confidential. </font></td>
</tr>
<tr>
<td align="CENTER" valign="TOP" bgcolor="#002041">
<font class="copyright"><font class="copyright_lnk" color="#FFFFFF" face="verdana" size="1">Copyright 2000.All rights reserved. </font></td>
</tr>
</tbody>
</table>
</body>
</html>
This is more of a question for the .net forum since you are using asp.net with vb.net. It could be any number of things. The code its self will run fast, its asp.net, it is precompiled and everything by the server. Sql server should be a fast db solution. Are you hosted with other users? Maybe the data base server and the webserver are just under a lot of load. That code is fairly simple, it shouldn't be lagging, its not like you are looping through an actual db table or something (a dataset would still be fast).
In a world without walls and fences - who needs Windows and Gates?! - Unknown Author
"And there's Bill Gates, the...most...famous...man in the...ah...Microsoft." -- A TV commentator for the 2000 Olympics.
Bookmarks