0

I have an excel workbook that is linked to an open Power BI file. The connection name is "mtbsql6??v-dev_mssqlinst01 PRS Model" and the connection string is

"Provider=MSOLAP.8;Integrated Security=SSPI;Persist Security Info=True;User ID="";Initial Catalog=2a527000-c71f-4b0d-8506-36d1799ec663;Data Source=localhost:6514?;Location=localhost:6514?;MDX Compatibility=1;Safety Options=2;MDX Missing Member Mode=Error;Update Isolation Level=2".

I need to update the local host number which I already have in a variable. Is it an OLEDB connection? Have tried some below code but it's failing. Got this code from another answer on stack overflow. It is failing on the line marked as ##.

 Dim ConnectionString As String
    ConnectionString = UpdatedString (This is stored in a variable)
    UpdateQueryConnectionString ConnectionString


Sub UpdateQueryConnectionString(ConnectionString As String)

  Dim cn As WorkbookConnection
  Dim oledbCn As OLEDBConnection
  Set cn = ThisWorkbook.Connections("mtbsql6??v-dev_mssqlinst01 PRS Model")
  Set oledbCn = cn.OLEDBConnection
  oledbCn.Connection = ConnectionString ###

End Sub

Thanks for any help.

1 Answer 1

1

You didn't mention what the error was... Might it be the quotes after User ID in your connection string?

UpdatedString = "Provider=MSOLAP.8;Integrated Security=SSPI;Persist Security Info=True;User ID=" & chr(34) & chr(34) & ";Initial Catalog=2a527000-c71f-4b0d-8506-36d1799ec663;Data Source=localhost:6514?;Location=localhost:6514?;MDX Compatibility=1;Safety Options=2;MDX Missing Member Mode=Error;Update Isolation Level=2"

Sign up to request clarification or add additional context in comments.

3 Comments

The error coming up is Run Time Error 1004, application defined or object defined error and the line oledbCn.Connection = ConnectionString shows the error.
Tried the Connection string with User ID=" & chr(34) & chr(34) & " but same error on same line
I feel that this connection is not an OLEDB connection..I wanted to try an approach like For Each conn In ActiveWorkbook.Connections With conn---------and then I want to refer the connection string as conn.something.connection string = UpdatedConnectionString, just this reference I can't figure out. Is it possible?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.