Link to home
Start Free TrialLog in
Avatar of Abbas Hayali
Abbas HayaliFlag for Iran, Islamic Republic of

asked on

macro

I created an provider driver for SQl server using the user login for authentication , and tested successfully . But when my vb code tries to access the filedsn I created it gives me an error , saying Runtime error '-2147217843 (80040e4d)',
the code is :
Sub main()
    Dim Db As ADODB.Connection
    Dim RS As ADODB.Recordset
    Dim CMD As ADODB.Command
       Set Db = New ADODB.Connection
       Set RS = New ADODB.Recordset
       Set CMD = New ADODB.Command
    Db.CursorLocation = adUseClient
    Db.Open "Provider=SQLNCLI11;server=server-pc;Database=IFS_803_13960820;UserId=farauser;Password=tycedar"

  CMD.ActiveConnection = Db
  CMD.CommandType = adCmdStoredProc
  CMD.CommandText = "__GASKARTPEYMAN__"
  CMD.Parameters.Append CMD.CreateParameter("@PNO", adInteger, adParamInput, 10, 31529)
   
 
 Set RS = CMD.Execute
   
   
End Sub
Avatar of Nakul Vachhrajani
Nakul Vachhrajani
Flag of India image

Just off the top of my head, the commandtext does not look right. If it begins with an underscore, you should wrap it in square brackets.

i.e. use:
CMD.CommandText = "[__GASKARTPEYMAN__]"

Open in new window


instead of:
CMD.CommandText = "__GASKARTPEYMAN__"

Open in new window

Avatar of Abbas Hayali

ASKER

Thanks
but this way dose not work because the error is on this line:

    Db.Open "Provider=SQLNCLI11;server=server-pc;Database=IFS_803_13960820;UserId=farauser;Password=tycedar"
Oh, I believe you do not have the correct connection string in this case. The connection string that you have is a DSN-less connection to a database that is hosted on an instance of SQL Server.

So, if your fileDSN is named "myfileDSN", you need:

Db.Open "fileDSN=myfileDSN"

Open in new window

Db.Open "Provider=SQLNCLI11;server=server-pc;Database=IFS_803_13960820;UserId=farauser;Password=tycedar"

Please check if the password is correct.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.