Sunday, February 12, 2012

ASP.NET and SQL Server Help

I was using this code yesterday on my SQL Server at home to insert values and everything was working fine.


Public Function doInsertPrimary(ByVal iState As String)
Dim sqlConnect As String
sqlConnect = "server = mySRVR; database = myDB; uid = sa; password = somepass"
Dim oConnection As New SqlClient.SqlConnection _
(sqlConnect)
Dim sqlString As String
sqlString = "INSERT INTO myTable VALUES (" & iState & ")"
Dim oCommand As New SqlClient.SqlCommand(sqlString, oConnection)
oConnection.Open()
Try
oCommand.ExecuteNonQuery()
Finally
oConnection.Close()
End Try
End Function

Today, when I do the insert on a new SQL Server, it is inserting the same values 5 times. I am not sure whether the problem is in my code or on the server. Can someone let me know where they think the problem is at?It's not your function. That's pretty basic. Somehow, it's getting called 5 times. Since it's not a stored procedure, there's no way there's some goofy T-SQL. I've found it's usually something with your page processing order. Button click calls a sub, but it's called in the page load, but that fires another one and you end up with multiple calls when you want one. Enable tracing, put a trace statement in yor function and see how many times it's called. Then try to figure out what's calling it multiple times.|||Here is something interesting that I forgot to mention:

I am running Virtual PC on the same laptop as .NET with Windows 2003 and Sql Server 2000 on it. Here at work, I have a second laptop as well. When I execute the same code on the remote laptop, everything executes perfectly. Hence, the code is fine. I enabled tracing, and the code is only being called once. Anyone know anything about this?

No comments:

Post a Comment