我一直在开发一个MS Access应用程序,它允许一些同事轻松地与我们的SQL Server上的数据进行交互。程序即将完成,但还有一件小事 - 允许用户通过MS Access前端更改其SQL Server密码。我一直在谷歌上搜索我的小心脏,但过了一会儿,一切都开始看起来一样(即使答案就在我面前!)。
我找到了一些有用的链接,但我无法完成如何将其应用到我的VBA程序上的飞跃。
Change expired password without "Password Expired dialog box"
How can I change SQL Server login account password on first login via C#?
http://www.utteraccess.com/forum/Users-Change-SQL-Pass-t2006545.html&pid=2378998
我当前的连接字符串如下所示
Dim cn As ADODB.Connection
Dim strCS As String
Set cn = New ADODB.Connection
strCS = "Provider=SQLOLEDB;" _
& "Server=IP ADDRESS GOES HERE;" _
& "Database=" + DBselect.Value + ";" _
& "User ID=" + Uname.Value + ";" _
& "Password=" + pWord.Value + ";" _
& "MARS Connection=True;"
cn.ConnectionString = strCS
cn.Open
只要用户的密码未过期,此连接字符串就可以正常工作。
如何修改此连接字符串以更改用户密码?任何帮助真的很感激!
谢谢!
答案 0 :(得分:2)
从第一个链接看起来,这将起作用:
1)在SQL Server中创建一个名为spChangeLogin的新存储过程。它应该是这样的:
CREATE procedure [dbo].[spChangeLogin]
@UserName VarChar (50),
@OldPass VarChar (20),
@NewPass VarChar (20)
AS
BEGIN
ALTER LOGIN @UserName WITH
PASSWORD = @NewPass
OLD_PASSWORD = @OldPass
END
;
GO
2)将其添加到Access DB:
Dim cnComments As New ADODB.Connection
Dim strCS As String
Dim P As String
Dim Rsx As ADODB.Recordset
'Set up the connection string
strCS = "Provider=SQLOLEDB;" _
& "Server=IP ADDRESS GOES HERE;" _
& "Database=" + DBselect.Value + ";" _
& "User ID=" + Uname.Value + ";" _
& "Password=" + pWord.Value + ";" _
& "MARS Connection=True;"
cnComments.Open strCS
P = "spChangeLogin '" & Me.UserName & "', '" & Me.OldPass & "', '" & Me.NewPass & "'"
Set Rsx = cnComments.Execute(P)
3)在表单上放置3个字段; UserName,OldPass和NewPass
Requires ALTER ANY LOGIN permission
注意:强>
我的连接字符串如下所示:
strConn = "PROVIDER=SQLOLEDB;DATA SOURCE=MyServerName;INITIAL CATALOG=MyDatabaseName;UID=GlobalUserID;PWD=GlobalPassword;"
您可能需要相应调整。