ADO fails to connect

Asked

Viewed 112 times

0

I have a project in Excel where I am trying to make a connection to SQL Server database. I am working on a virtual machine and the database is on another machine, however they are all on the network, I have checked the IP of the machine where the database is and it is accessible from the virtual machine, but every time I try to make the connection to the database in VBA it fails.

and me Returns the following error;

[DBNETLIB] [Connectionopen(Connect()). ] SQL Server missing or denied access

below is my code!

Private Sub RoundRect2_Click() 

    Dim Cn As ADODB.Connection
    Dim Server_Name As String
    Dim Database_Name As String
    Dim User_ID As String
    Dim Password As String
    Dim SQLStr As String
    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset

    Server_Name = "192.168.120.152:49172" ' Enter your server name here
    Database_Name = "teste" ' Enter your database name here
    User_ID = "root" ' enter your user ID here
    Password = "1234" ' Enter your password here
    SQLStr = "SELECT * FROM cod" ' Enter your SQL here

    Set Cn = New ADODB.Connection
    Cn.Open "Provider=SQLOLEDB;Server=" & Server_Name & ";Database=" & Database_Name & _
";Uid=" & User_ID & ";Pwd=" & Password & ";"

    rs.Open SQLStr, Cn, adOpenStatic

End Sub
  • And the mistake that is?

  • [DBNETLIB] [Connectionopen(Connect()). ] SQL Server missing or access denied

  • by chance where your bank is you have already given proper security permissions?

  • I believe so, because I am connected in it by Datagrip

  • The IDE connects normal but if you don’t give the proper permissions to the database where it is rarely will be able to use by applications!

1 answer

2


Problem solved, in the server_name was using : to separate the connection port, but the correct one is to use ,.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.