1

I am trying to connect to a SQL via VBA Code on Excel.

The problem is that when I am logged in on my username, I can connect to the database without problem. But when I try to connect with other user logged in, the connection is unsucessful.

I have already created a user inside my Database, like the picture below:

User Created on Database

And my connection on VBA is being done this way:

Option Explicit

Public DB As New ADODB.Connection
Public RST As New ADODB.Recordset
Public caminho, strConn As String
Public Msg As String

Sub CONECTA_DB()

strConn = "Provider=SQLOLEDB;Data Source=BR1104053\SQLEXPRESS;" & _
          "Initial Catalog=BDVestiario;" & _
          "Integrated Security=SSPI;" & _
          "User ID=bdvestiario;" & _
          "Password=#infra#sudeste#;"


Set DB = New ADODB.Connection
Set RST = New ADODB.Recordset

DB.Open strConn

RST.CursorLocation = adUseClient

This gives a connection error when logged on other user, but connects normally when I am loggen on my user.

The problem, is that I need all my company to use this excel sheet connecting to SQL, so I need a common username to read and write on the database.

1
  • It probably doesn't really matter in this case (or does it?), but I'd strongly recommend you redact passwords/credentials when you post anything online. Feel free to edit it out, and note you can flag it for moderator attention, to get the revision history redacted, if you need to (same with the answer you got) Commented Apr 13, 2017 at 20:14

1 Answer 1

2

You need to set Integrated Security to false or removed completely from your connection string. When this is true or SSIS Windows credentials are used.

strConn = "Provider=SQLOLEDB;Data Source=BR1104053\SQLEXPRESS;" & _
      "Initial Catalog=BDVestiario;" & _
      "User ID=bdvestiario;" & _
      "Password=#infra#sudeste#;"
Sign up to request clarification or add additional context in comments.

3 Comments

I have tried this, but still have no success. I received a failed logon message with the 'bdvestiario' user when I try this. Maybe I'm creating the user on the wrong way on SQL Server? @jradich1234
I just noticed that you're using SQL Express. Have you configured the SQL Express server to allow remote connections? It does not allow them by default. Here's a link on how to enable remote connections.
thanks @jradich1234...I have already done this too...but I discovered the problem. I didn't restart the server after created the new logon. After the restart it worked perfectly! Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.