Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

access to database two times, same page, same object?

Status
Not open for further replies.

kybbe

Programmer
Sep 28, 2003
2
SE
Hi!

I have a situation where I access an SQL Server 2000
database two times one the same page, via the
same "command object". First through a stored procedure
then via "ordinary asp sql query".

Could someone please tell me if I use good/efficient
coding here, it works well and I have had no problem with
it. But after reading some articles I´m not sure if it´s
better coding to close the command object after executing
the stored procedure and then declare a new one for
the "ordinary asp sql query"?
(including the second query into the stored procedure is not an option)

Here is a "compressed" version of my code:


Set MyConec=Server.CreateObject("ADODB.Connection")
constr="Driver=SQL Server; Data Source=myDatasource; User ID=myUserID; Password=myPassword"
DataAnslutn.Open constr


Set ComObj = Server.CreateObject("ADODB.Command")

With ComObj
.ActiveConnection = MyConec
.CommandText = "SP_name"
.CommandType = adCmdStoredProc

.Parameters.Append .CreateParameter ("NeededValue", adInteger, adParamReturnValue)
.Parameters.Append .CreateParameter ("@Name", adVarChar, adParamInput, 255, Name)
.Parameters.Append .CreateParameter ("@InputNumber", adInteger, adParamInput, , InputNumber)
.Parameters.Append .CreateParameter("@new_id", adInteger, adParamOutput)

.Execute, , adExecuteNoRecords

NeededValue=ComObj(0)

If NeededValue = 0 Then
new_id = .Parameters("@new_id")

SQL = SQL & " INSERT INTO myTable (Value1,myID,InputNumber) VALUES "
SQL = SQL & "(" & Value1 & "," & new_id & "," & InputNumber & ")"

.CommandText = SQL
.CommandType = adCmdText

.Execute, , adExecuteNoRecords

End If

End With

MyConec.Close
Set MyConec = Nothing
Set ComObj = Nothing


Grateful for comments on this

Thanks in advance
/Anders
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top