D
darkstar
I've been stuck on this for a few days now, so I hope someone here can
help
Basically, I would like to connect to the ProjectServer_Published
database (read only) and check the current user's credentials in order
to apply the appropriate filter when certain projects are opened in
Project 2007 Professional. I'm using the RES_CODE field in the
MSP_RESOURCES table to store the access level information. The
following code works fine when using my own (or another admin's)
logon:
Dim Conn As New ADODB.Connection
Dim rs As ADODB.Recordset
Dim CurrentUser As String
CurrentUser = Environ("USERNAME")
'Create Connection
Set Conn = New ADODB.Connection
Set rs = New ADODB.Recordset
Conn.ConnectionString = "Provider=sqloledb;" _
& "Data Source=SQL_Server\SQL_Instance;" _
& "Initial Catalog=ProjectServer_Published;" _
& "Integrated Security=SSPI;"
Conn.Open
'Open recordset
rs.Open "SELECT RES_CODE, RES_NAME FROM MSP_RESOURCES", Conn
and so on... The filter is then applied for the RES_NAME that matches
CurrentUser based on the value in the RES_CODE field.
Since the connection works only for users with datareader permissions,
for regular users I need to impersonate an Admin account in order to
run the SQL connection and query. Our SQL servers use Windows
authentication exclusively, so passing SQL user IDs and passwords in
the connection string is not an option.
I have learned that I need to use the LogonUser,
ImpersonateLoggedOnUser, RevertToSelf, etc. functions of the advanced
Windows API (advapi32.dll), but I haven't been able to construct the
proper combination of code to make it work. Sometimes I got the
following error:
"Can't find DLL entry point LogonUser in advapi32.dll"
and sometimes the SQL server rejects the connection because it won't
accept "anonymous logins" (even though the Admin user ID and password
is provided).
Does anyone have any suggestions (or code) to make impersonation work
in VBA? Thanks in advance for any and all help.
help
Basically, I would like to connect to the ProjectServer_Published
database (read only) and check the current user's credentials in order
to apply the appropriate filter when certain projects are opened in
Project 2007 Professional. I'm using the RES_CODE field in the
MSP_RESOURCES table to store the access level information. The
following code works fine when using my own (or another admin's)
logon:
Dim Conn As New ADODB.Connection
Dim rs As ADODB.Recordset
Dim CurrentUser As String
CurrentUser = Environ("USERNAME")
'Create Connection
Set Conn = New ADODB.Connection
Set rs = New ADODB.Recordset
Conn.ConnectionString = "Provider=sqloledb;" _
& "Data Source=SQL_Server\SQL_Instance;" _
& "Initial Catalog=ProjectServer_Published;" _
& "Integrated Security=SSPI;"
Conn.Open
'Open recordset
rs.Open "SELECT RES_CODE, RES_NAME FROM MSP_RESOURCES", Conn
and so on... The filter is then applied for the RES_NAME that matches
CurrentUser based on the value in the RES_CODE field.
Since the connection works only for users with datareader permissions,
for regular users I need to impersonate an Admin account in order to
run the SQL connection and query. Our SQL servers use Windows
authentication exclusively, so passing SQL user IDs and passwords in
the connection string is not an option.
I have learned that I need to use the LogonUser,
ImpersonateLoggedOnUser, RevertToSelf, etc. functions of the advanced
Windows API (advapi32.dll), but I haven't been able to construct the
proper combination of code to make it work. Sometimes I got the
following error:
"Can't find DLL entry point LogonUser in advapi32.dll"
and sometimes the SQL server rejects the connection because it won't
accept "anonymous logins" (even though the Admin user ID and password
is provided).
Does anyone have any suggestions (or code) to make impersonation work
in VBA? Thanks in advance for any and all help.