结束与 cnPubs.Close 设置rsPubs1 =没有With rsPubs1.ActiveConnection = cnPubs.Open "SELECT QUERY" 'Sheet1.Range("A1").CopyFromRecordset rsPubs1.CloseEnd WithcnPubs.CloseSet rsPubs1 = Nothing 需要帮助:我有两个服务器 - 服务器A和服务器B.一个是主要/主要,一个是次要/镜像。我想在代码中添加以下功能 -检查服务器A是否为主体,如果是 - >打开与服务器A的连接并执行select语句 否则检查服务器B是否为Principal,如果是 - >打开与服务器B的连接并执行select语句 否则关闭所有连接Check if server A is principal , If yes --> open connection to server A and execute select statementElse check if server B is Principal, If yes --> open connection to server B and execute the select statementElse close all connections我尝试使用此格式但是它不受支持。给出错误 - incorect属性I tried using this format but it is not supported . Gives error - incorect attributes设置cnPubs = CreateObject(" ADODB.Connection")Set cnPubs = CreateObject("ADODB.Connection") cnPubs.Open" Provider = sqloledb;" &安培; _ "数据源= ServerA;" &安培; _ " Failover_Partner = ServerB;" &安培; _ $ " Network = dbmssocn;" &安培; _ $ " Initial Catalog = dbname;" &安培; _ " INTEGRATED SECURITY = sspi;"cnPubs.Open "Provider=sqloledb;" & _"Data Source=ServerA;" & _"Failover_Partner=ServerB;" & _"Network=dbmssocn;" & _"Initial Catalog=dbname;" & _" INTEGRATED SECURITY=sspi;"推荐答案 我认为镜像服务器会自动进行故障转移,因此不需要这样做。如果不是这样,我怀疑你需要在SQL Server论坛上重复这个问题,因为还没有人回答你的问题。I thought mirror servers would automatically failover, so no need for this. If this isn't true, I suspect you need to repeat the question on a SQL Server forum given that no one as answered your question yet.为了更简单,更容易阅读和维护代码,我将设置对Microsoft ActiveX Data Objects库2.8的引用,然后您的代码变为:For simpler and easier to read and maintain code, I would set a reference to the Microsoft ActiveX Data Objects library 2.8 then your code becomes:Sub Test()Dim cnPubs As New ADODB.ConnectionDim rsPubs1 As New ADODB.Recordset cnPubs.Open "Provider=sqloledb;" & _ "Data Source=ServerA;" & _ "Initial Catalog=DBname;" & _ " INTEGRATED SECURITY=sspi;" rsPubs1.Open "SELECT Query", cnPubs, adOpenKeyset, adLockOptimistic Sheet1.Range("A1").CopyFromRecordset rsPubs1 rsPubs1.Close cnPubs.Close Set rsPubs1 = NothingEnd Sub 这篇关于将数据从SQL Server导入Excel 2010 - principal / mirror的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-02 16:00