This article was previously published under Q186383
This article has been archived. It is offered "as is" and will no longer be updated.
This article describes the technique required for the MFC CDao classes toaccess Microsoft SQL Server data that is password protected through anattached table in Microsoft Access without getting the ODBC password dialogbox. The article describes how to programmatically specify the ODBCconnection string to the attached table. You must create a CDaoTableDef,set the ODBC connect string, and refresh the TableDef.
To reproduce the problem and create a solution, do the following:
From SQL Server Enterprise Manager select "manage logins," and add user"billy" with password "Reuben". Select Databases/Pubs/Groups-users/Public,right-click to select Add user. Add billy (with login Billy), refresh thepublic icon, right-click billy, and then select permissions. Select theauthors table, select each field (you will get a green check markindicating that you have been granted permission), and then click Set.
Create a new DSN to the pubs database. From the ODBC administrator, selectAdd. Select the SQL Server driver. Call the new DSN _pubsSecure. On thequestion "How should SQL Server verify the authenticity of the login ID?,"change the button to "With SQL Server authentication using a login ID andpassword entered by the user." Change the Login ID to billy and specifyReubin for the password. Leave the rest of the defaults.
Create an Access database. Select the Table tab, click New, and then clicklink table. In the "Files of type" list box, select "ODBC Databases()".Select the Machine Data Source tab, and then select "_pubsSecure". You willbe prompted for the password. Select the "dbo.authors" table. Save thedatabase as C:\Temp\daoSqlTest.mdb. Close Access, restart access, and thenopen daoSqlTest.mdb. You will be prompted for a password. This verifiesthat your security is set up correctly.
Create a MFC/CDao AppWizard Database project. Call it ASAuth (for AccessSQL Authorize), select daoSqlTest.mdb, and then select the authors table.Build and run the application. You will get the ODBC "SQL Server Login"dialog box, which requests the password. Enter the password and the programwill open the Recordset. This verifies your previous steps.