What's wrong with this code
Hi,
I got an ado code which I am running from Access 2000 front end. THis code is supposed to run a stored procedure on sql server backend by passing parameters to update records. However, I am getting the error message Sql server does not exist or access denied. I am running the sql server on local machine. I know that the userid and password is correct. However, I have no idea why I am having this problem. I would appreciate any help on this matter. Thanks in advance.
CODE:
Private Sub cmdRunProc_Click()
Dim conn As ADODB.Connection
Dim cmdUpdate As ADODB.Command
Dim lngRecs
Dim strType
Dim curPercent
Set conn = New ADODB.Connection
Set cmdUpdate = New ADODB.Command
myDSN = "Provider=SQLOLEDB;Data Source=sqlpubs; " & _
"Initial Catalog=pubs; user id=sa; password=alloyd"
conn.Open myDSN
Set cmdUpdate.ActiveConnection = conn
' Get the form values
strType = Forms!frmParamPassing!txtBookType
curPercent = Forms!frmParamPassing!txtPercent
' Set the properties of the command
With cmdUpdate
.ActiveConnection = conn
.CommandText = "usp_UpdatePrices"
.CommandType = adCmdStoredProc
' Add the parameters
.Parameters.Append .CreateParameter("@Type", adVarWChar, adParamInput, 12, strType)
.Parameters.Append .CreateParameter("@Percent", adCurrency, adParamInput, , curPercent)
' Execute the command
.Execute lngRecs, , adExecuteNoRecords
End With
' And finally tell the user what's happened
MsgBox ("Procedure complete. Records were updated")
Set conn = Nothing
Set cmdUpdate = Nothing
End Sub
|