|
|
|
| Была у меня в Access 2003 функция смены юзера базы
Public Function ChangeUser(Optional varDSN As String = vbNullString, Optional varUser As String = vbNullString, Optional varPwd As String = vbNullString) As Boolean
' èçìåíÿåò òåêóùåãî ïîëüçîâàòåëÿ
'
' Âõîä:
' varDSN - èìÿ áàçû
' varUser - èìÿ ïîëüçîâàòåëÿ
' varPwd - ïàðîëü
Dim dbase As dao.Database
Dim strConnect As String
On Error GoTo Err_Debug
ChangeUser = True
Set conn = New ADODB.Connection ' óñòàíîâèòü ñîåäèíåíèå, ïðè îøèáêå âûéòè èç ïðèëîæåíèÿ
If Len(varDSN) > 0 Then
conn.ConnectionString = "DSN=" & varDSN & ";"
End If
If Len(varUser) > 0 Then
conn.ConnectionString = conn.ConnectionString & "UID=" & varUser & ";"
End If
If Len(varPwd) > 0 Then
conn.ConnectionString = conn.ConnectionString & "PWD=" & varPwd & ";"
End If
conn.Properties("Prompt") = adPromptCompleteRequired
Me.SetFocus
Me.Visible = False
conn.Open
strConnect = right$(conn.ConnectionString, Len(conn.ConnectionString) - InStr(conn.ConnectionString, """"))
strConnect = Left(strConnect, Len(strConnect) - 1)
Set dbase = DBEngine.Workspaces(0).OpenDatabase("", dbDriverPrompt, False, strConnect)
WaitEndProces
Me.varCurrentUser = UCase(servDLookUp(varConnect:=conn, Expr:="USER", Domain:="DUAL"))
Me.varCurrentUserLevel = Nz(servDLookUp(varConnect:=conn, Expr:="USER_ACCESS_LEVEL", Domain:="STRATEGY.OPER_USER_DESC", Criteria:="UPPER(USER_NAME)='" & Me.varCurrentUser & "'"), 4)
Exit_Here:
Set dbase = Nothing
Exit Function
Err_Debug:
ChangeUser = False
If Err.Number = -2147217842 Then
DoCmd.Quit
Else
MsgBox Err.Description
End If
Resume Exit_Here
End Function
|
WaitEndProces - это обертка для DoEvents
в 2007 не хотит работать
conn.ConnectionString = "Provider=MSDASQL.1;" а про всяхие DNS, USER и т.д. забывает.
Кто сталкивался? | |
|
|