ADO SQL Query - Multi Users, Schema Name Required?

bs0d

Well-known Member
Joined
Dec 29, 2006
Messages
622
I created an Excel workbook that uses ADO query a database on our SQL server:
Code:
    Set myConn = New ADODB.Connection
    Set myRS = New ADODB.Recordset

    strConn = "PROVIDER=SQLOLEDB;DATA SOURCE=db_server_name;INITIAL CATALOG=database_name;INTEGRATED SECURITY=sspi;"

    myConn.Open strConn
    myRS.Open sSQL, myConn, adOpenStatic, adLockReadOnly, adCmdText

I have an ODBC connection for the "database_name". I'm able to query the database just fine without using prefacing each table name reference with the schema name. However, when another user executes queries in the workbook, they get the "invalid object name" error - and it specifies the table name ad invalid. If I update the code to xxx.table_name (where xxx = the schema), the error goes away.

If they're using the same credentials to access the SQL database, why would they be seeing this error? Google search results indicate many need to CTRL+SHIFT+R the IntelliSense in SQL Serve Management Studio-- But I don't have access to that. This is all through Excel. Is there a time period that must pass before IntelliSense is refreshed on its own? Anyone else work through this unique experience?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
I created an Excel workbook that uses ADO query a database on our SQL server:
Code:
    Set myConn = New ADODB.Connection
    Set myRS = New ADODB.Recordset

    strConn = "PROVIDER=SQLOLEDB;DATA SOURCE=db_server_name;INITIAL CATALOG=database_name;INTEGRATED SECURITY=sspi;"

    myConn.Open strConn
    myRS.Open sSQL, myConn, adOpenStatic, adLockReadOnly, adCmdText

I have an ODBC connection for the "database_name". I'm able to query the database just fine without using prefacing each table name reference with the schema name. However, when another user executes queries in the workbook, they get the "invalid object name" error - and it specifies the table name ad invalid. If I update the code to xxx.table_name (where xxx = the schema), the error goes away.

If they're using the same credentials to access the SQL database, why would they be seeing this error? Google search results indicate many need to CTRL+SHIFT+R the IntelliSense in SQL Serve Management Studio-- But I don't have access to that. This is all through Excel. Is there a time period that must pass before IntelliSense is refreshed on its own? Anyone else work through this unique experience?

What I found was that INTEGRATED SECURITY-sspi means to use Windows authentication. So regardless of how your ODBC is setup, the code runs Windows authentication to access the data. Further, only the owner of the schema may reference tables without the schema name. If another user is executing a query, the schema is required. INTEGRATED SECURITY-SSPI is recommended, but I suppose this post should provide some clarity on invalid object name errors an schema.
 
Upvote 0

Forum statistics

Threads
1,212,927
Messages
6,110,700
Members
448,293
Latest member
jin kazuya

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top