如何在宏中硬编码技术用户的凭据

时间:2016-12-17 12:56:54

标签: sql-server excel macros connection-string

我正在使用宏在sql server中执行存储过程,该服务器返回一些数据:

Sql = "EXEC [dbo].[p_adhoc_reporting_sre] @as_of = '"
Sql = Sql + asof + "'"

ActiveWorkbook.Worksheets.Add


With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array( _
    "OLEDB;Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=FRPCREDIT_Summix_fsdb;Data Source=CHRV40" _
    , _
    "18\PIN4018;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=CHR5AFC7;Use Encryption for Data=Fals" _
    , "e;Tag with column collation when possible=False"), Destination:=Range( _
    "$A$1")).QueryTable
    .CommandType = xlCmdSql
    .CommandText = Array(Sql)
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .PreserveColumnInfo = True
    .Refresh BackgroundQuery:=False
End With

这是使用当前用户的凭据进行身份验证,但我想将其替换为技术用户的凭据。将用户ID和密码添加到连接字符串没有帮助,并继续使用用户的凭据。删除“Integrated Security = SSPI”会使技术用户的凭据被提取,但无法连接。我是否需要在连接字符串中添加其他内容?

感谢。

0 个答案:

没有答案