A family of Microsoft relational database management systems designed for ease of use.
Keep in mind that the code not supposed to "show" any tripped errors - but it is supposed to run the on-error part if the uid/pass is NOT valid.
Sorry, I did a bit of “air” code in that sql logon,
You have to change the sql to say something like this:
qdf.SQL = "select 'abc' "
My sorry for messing that up. (so change the code to above line).
So modify the code to above. You can use “any” valid sql – and I used one that does NOT reference or select any table. So this routine can be used for all databases and you don’t have to use some “known” table name.
So change the above, and then you can go:
Dim strCon As String
strCon = "ODBC;DRIVER={sql server};" & _
"SERVER=ALBERTKALLAL-PC\SQLEXPRESS;" & _
"DATABASE=test3;" & _
"UID=SA;" & _
"PWD=MyPassWord;" & _
"APP=Microsoft Office;" & _
"WSID=AlbertKallal-pc;"
Debug.Print TestLogin(strCon)
NOTE:
If you do at ANY TIME provide a VALID logon to the above routine, then AFTER that point you can send any BAD or non-valid logon, and it will CONTINUE to return true and continue to WORK!!!! This is because of that “caching” system that access uses and outlined by Ben. However even if not using that caching trick, you still find that Access will cache passwords.
What above means is that once you logged on, then that’s quite much it – you can’t logoff. You are 100% done! You will have to exit the database for that given UID/Password to stop working.
And passing “different” UID/Password will not fail - even if wrong!. This is EXTREMELY important during development, since if you are developing some code, logon with a valid UID/pass, and then run some re-link code to re-link the tables with a different uid/pass? You can actually wind up re-linking the table(s) with a BAD uid/pass word that does not work, and yet you find the application runs fine – fine that is until you exit and re-enter.
For the above reason, if you are playing and testing code to link to a database and then must re-link – I STRONG recommend you exit and then re-enter the database to flush out any cached uid/password you been using or testing with. This occurs FAR MORE common then you realize, since for example you might be testing code while linked to the “test” or “developer” database, and right before deployment you now want to link to the production database. You in this case REALLY REALLY REALLY want to exit the database to flush out that cached uid/password before you re-link to production (else as noted you have linked tables that “seem” to work, but were actually linked and working using an incorrect + older uid/password. You also find this behavior if you trying to re-link existing tables that included the uid/pass, and the new re-linking is to remove the uid/pass. You find that you can freely click on and open those tables without a uid/logon, yet the linked tables dont' have a uid/pass!!!!
Regards,
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
******@msn.com