0

I am a .Net / SQL Server programmer. I am trying to make an Access database created by someone else to work. It looks like is uses a procedure similar to Save password for ODBC connection to SQL Server from MS Access 2007 but I am using Access 2003 so I suspect something else needs to be done. I don't really know what I am doing with Access but I am stuck with it.

I do have an ODBC connection and it looks like the linked tables use it. The database has an AutoExec which populates some local tables from the linked tables that the reports use. It also calls a qryConnect with a dsn-less connection like the linked article and this seems to work. I have got it to stop asking for a user and password on start up. I can also open most reports without problems, 2 do not work. A form loads on Startup with buttons that basically show reports. This is where it gets odd.

The reports fail from the ODBC driver with the windows credentials. Then a logon box shows up with the correct user (a user with read only privileges) but the trusted connection box is checked. I do not have the trusted box checked in the DSN. Not do I have Trusted_Connection=Yes in the DSN-less connection in qryConnect.

This is the code in the form

stDocName = "rptNegativeLotQtys"
DoCmd.OpenReport stDocName, acPreview

I don't know how I buggered it up so much and before I try again copying everything to a new mdb and trying again I am hoping to get some guidance.

On a side note I can open everything fine on my machine. I am an administrator as far as Windows is concerned but not SQL Server.

EDIT: I created a new DSN just for these reports. Then I deleted all linked tables and re-linked then using the new DSN. I looked at the linked tables in MsysObjects and the new DSN is listed there. Yet Access still prompts for the password. It appears that it is not caching the password.

Community
  • 1
  • 1
Joe
  • 379
  • 1
  • 6
  • 21

1 Answers1

0

Actually, you do NOT need to add nor store the UID/Pass in the connection strings used. However, what you MUST ensure is that all connection strings are the SAME. If they are different, then the cached UID/password will not work.

Also, make sure you do NOT connect nor open a table AFTER having connected using Windows Auth – the reason being then when you add the table links (especially via code), then the cached setup of using windows auth will occur, and thus prompts will occur when the links suggest to do otherwise. In other words linking and attempted to use SQL logons will NOT work if you already opened any table link via windows auth (so exit the database and do NOT open any table that could/can use windows auth).

So I would delete the links, and re-create them – but again, ensure that you never connected as a windows auth user to SQL server.

So the "cache" that access has is a GREAT friend/feature to eliminate the need to include UID/pass in the connection string - but the SAME feature will bite you VERY bad if you at any time connecte to the database in question via windows auth.

How to “cache” the user logon and ID is explained here:

Power Tip: Improve the security of database connections

http://blogs.office.com/b/microsoft-access/archive/2011/04/08/power-tip-improve-the-security-of-database-connections.aspx

So you “can” include the UID/LOGON in the linked tables, but above shows that a ONE time logon can also be used. So be VERY careful when setting up table links – due to the above “cache” of the user and HOW they logged into the database – code that ATTEMPTS to create table links based SQL logons will actually wind up using windows auth if you already connected as such (so exit the database if you going to re-link using SQL logons).

Keep in mind, Access does NOT use the DSN AFTER you linked the table. The information from the DSN is a ONE TIME copy to the connection string. You can verify this by going into my documents and deleting the DSN you used. Assuming the linked table was working correctly, you find that they CONTINUE to work EVEN if you delete the DSN. In effect this means that linked tables are DSN less except for when you create the linked table. This allows you to easy copy the application to different computers without having to copy the DSN.

As to ensure that all the linked tables use the same connection string, it is a simple matter to delete them all, and re-link.

You can also hit ctrl-g to bring up the debug window, and look at the connection string this way:

? currentdb.TableDefs("linked table name").Connect

the result in the debug window for a windows auth connection string will look like this:

ODBC;Description=test DSN;DRIVER=SQL Server;
SERVER=albertkallal-pc\SQLEXPRESS;
Trusted_Connection=Yes;
APP=Microsoft Office 2010;DATABASE=AxisMIS

Note how in above we see "trusted connection" (that means windows auth).

If I linked the table using SQL logon (and REMEMBER to check save password), then you see this:

ODBC;Description=TEST3;DRIVER=SQL Server;
SERVER=ALBERTKALLAL-PC\SQLEXPRESS;
UID=MySQLogon;PWD=MyPassword;
APP=Microsoft Office 2010;DATABASE=AxisMIS

Just remember during the table link process to "check" the save password.

eg this: enter image description here

Albert D. Kallal
  • 42,205
  • 3
  • 34
  • 51
  • Linked tables require a DSN so I do not know if that is an issue. I deleted the DSN I created and checked the Connect field in Sysobjects. How do I determine if the connection string Access is using is the "same"? It is impossible to connect as a windows auth user to SQL Server since we have no Windows users that match SQL server users. However when I open the database it prompts me with a logon dialog with my Windows User ID in it. – Joe Jan 04 '16 at 15:47
  • You not noted if you using windows auth, or you want to use SQL logons. – Albert D. Kallal Jan 04 '16 at 23:26
  • Keep in mind, Access does NOT use the DSN AFTER you linked the table. The information from the DSN is a ONE TIME copy to the connection string. You can verify this by going into my documents and deleting the DSN you used. Assuming the linked table was working correctly, you find that they CONTINUE to work EVEN if you delete the DSN. In effect this means that linked tables are DSN less except for when you create the linked table. (so linked tables DO NOT require a DSN). This allows you to easy copy the application to different computers without having to copy the DSN. – Albert D. Kallal Jan 04 '16 at 23:27