Skip to content

Commit 22f2726

Browse files
committed
Added check for MSOLAP driver.
Added heuristic to create a valid ODC file.
1 parent 8debe93 commit 22f2726

8 files changed

Lines changed: 111 additions & 26 deletions

File tree

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<item>
3-
<version>1.0.2.0</version>
4-
<url>https://cdn.sqlbi.com/updates/AnalyzeInExcel-1.0.2.msi</url>
3+
<version>1.0.4.0</version>
4+
<url>https://cdn.sqlbi.com/updates/AnalyzeInExcel-1.0.4.msi</url>
55
<changelog>https://github.com/sql-bi/AnalyzeInExcel/releases/</changelog>
66
<mandatory>false</mandatory>
77
</item>

AnalyzeInExcel/App.xaml.cs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace AnalyzeInExcel
1515
public partial class App : Application
1616
{
1717
public Options AppOptions;
18+
const string MSOLAP_DRIVER_URL = @"https://go.microsoft.com/fwlink/?LinkId=746283";
1819

1920
public void CheckUpdates(bool synchronous = true)
2021
{
@@ -45,6 +46,10 @@ public MessageBoxResult ShowMessage( string message )
4546
{
4647
return MessageBox.Show(message, "Analyze in Excel for Power BI Desktop");
4748
}
49+
public MessageBoxResult ShowMessageQuestion(string message)
50+
{
51+
return MessageBox.Show(message, "Analyze in Excel for Power BI Desktop",MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes);
52+
}
4853

4954
protected override void OnStartup(StartupEventArgs e)
5055
{
@@ -63,7 +68,27 @@ protected override void OnStartup(StartupEventArgs e)
6368
{
6469
string serverName = ((App)Application.Current).AppOptions?.Server;
6570
string databaseName = ((App)Application.Current).AppOptions?.Database;
66-
string cubeName = ModelHelper.GetModelName(serverName, databaseName, th);
71+
bool goodMsOlapDriver = ModelHelper.HasMsOlapDriver();
72+
if (!goodMsOlapDriver)
73+
{
74+
th.TrackEvent("MSOLAP driver not found");
75+
if (ShowMessageQuestion($"Excel needs a component called MSOLAP driver to connect to Power BI. The MSOLAP driver might be missing or not updated on this device. Therefore, Excel might not connect to Power BI. You can install the updated Microsoft MSOLAP driver from this link: {MSOLAP_DRIVER_URL} \n\nClick YES if you want to download the updated MSOLAP driver and install it.\nClick NO to continue without any update.") == MessageBoxResult.Yes)
76+
{
77+
try
78+
{
79+
th.TrackEvent("Requested MSOLAP driver setup");
80+
UpdateMsOlapDriver();
81+
}
82+
catch (Exception ex)
83+
{
84+
// Send any exception to Telemetry
85+
th.TrackException(ex);
86+
ShowMessage($"Error running MSOLAP update: {ex.Message}");
87+
}
88+
}
89+
}
90+
// We use the default "Model" string if the MSOLAP driver is not available - if this happens, the previous warning helps understanding possible issues
91+
string cubeName = goodMsOlapDriver ? ModelHelper.GetModelName(serverName, databaseName, th) : "Model";
6792
if (serverName != null && databaseName != null)
6893
{
6994
try
@@ -121,6 +146,17 @@ protected override void OnStartup(StartupEventArgs e)
121146
throw;
122147
}
123148

149+
void UpdateMsOlapDriver()
150+
{
151+
var p = new Process
152+
{
153+
StartInfo = new ProcessStartInfo(MSOLAP_DRIVER_URL)
154+
{
155+
UseShellExecute = true
156+
}
157+
};
158+
p.Start();
159+
}
124160
}
125161
private void OpenDiagnosticWindow(string serverName, string databaseName)
126162
{
@@ -141,8 +177,7 @@ Check that the file
141177
private void RunExcelProcess(string serverName, string databaseName, string cubeName)
142178
{
143179
// Create ODC file
144-
OdcHelper.CreateOdcFile(serverName, databaseName, cubeName);
145-
var fileName = OdcHelper.OdcFilePath();
180+
var fileName = OdcHelper.CreateOdcFile(serverName, databaseName, cubeName);
146181

147182
// Open ODC file
148183
var p = new Process

AnalyzeInExcel/ModelHelper.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace AnalyzeInExcel
99
{
1010
public class ModelHelper
1111
{
12+
const string MSOLAP_DRIVER_NAME = "MSOLAP"; // We get the latest available. We currently don't enforce MSOLAP.8
13+
1214
internal enum AsInstanceType
1315
{
1416
Other,
@@ -43,6 +45,26 @@ internal static AsInstanceType GetAsInstanceType(string dataSourceUri)
4345
return AsInstanceType.Other;
4446
}
4547

48+
/// <summary>
49+
/// Check whether the machine has the MSOLAP driver installed
50+
/// The driver could be available in 32-bit and not in 64-bit
51+
/// This would work in Excel, but it is better to try get the driver in that case
52+
/// </summary>
53+
/// <returns></returns>
54+
public static bool HasMsOlapDriver()
55+
{
56+
const string SOURCES_NAME = "SOURCES_NAME";
57+
58+
var oleEnum = new OleDbEnumerator();
59+
var elems = oleEnum.GetElements();
60+
if (elems != null && elems.Rows != null)
61+
foreach (System.Data.DataRow row in elems.Rows)
62+
if (!row.IsNull(SOURCES_NAME) && row[SOURCES_NAME] is string)
63+
if (row[SOURCES_NAME].ToString() == MSOLAP_DRIVER_NAME )
64+
return true;
65+
return false;
66+
}
67+
4668
/// <summary>
4769
/// Returns the OLE DB connection string based on serverName and databaseName
4870
/// </summary>
@@ -56,16 +78,16 @@ public static string GetOleDbConnectionString( string serverName, string databas
5678
switch (GetAsInstanceType(serverName))
5779
{
5880
case AsInstanceType.PbiDataset: // Integrated Security=ClaimsToken;
59-
connectionString = $"Provider=MSOLAP;Persist Security Info=True;Initial Catalog=sobe_wowvirtualserver-{databaseName};Data Source={serverName};MDX Compatibility=1;Safety Options=2;MDX Missing Member Mode=Error;Identity Provider=https://login.microsoftonline.com/common, https://analysis.windows.net/powerbi/api, 929d0ec0-7a41-4b1e-bc7c-b754a28bddcc;Update Isolation Level=2";
81+
connectionString = $"Provider={MSOLAP_DRIVER_NAME};Persist Security Info=True;Initial Catalog=sobe_wowvirtualserver-{databaseName};Data Source={serverName};MDX Compatibility=1;Safety Options=2;MDX Missing Member Mode=Error;Identity Provider=https://login.microsoftonline.com/common, https://analysis.windows.net/powerbi/api, 929d0ec0-7a41-4b1e-bc7c-b754a28bddcc;Update Isolation Level=2";
6082
break;
6183
case AsInstanceType.PbiDedicated:
6284
case AsInstanceType.PbiPremium:
6385
case AsInstanceType.AsAzure:
64-
connectionString = $"Provider=MSOLAP;Persist Security Info=True;Data Source={serverName};Update Isolation Level=2;Initial Catalog={databaseName}";
86+
connectionString = $"Provider={MSOLAP_DRIVER_NAME};Persist Security Info=True;Data Source={serverName};Update Isolation Level=2;Initial Catalog={databaseName}";
6587
break;
6688
case AsInstanceType.Other:
6789
default:
68-
connectionString = $"Provider=MSOLAP;Integrated Security=SSPI;Persist Security Info=True;Data Source={serverName};Update Isolation Level=2;Initial Catalog={databaseName}";
90+
connectionString = $"Provider={MSOLAP_DRIVER_NAME};Integrated Security=SSPI;Persist Security Info=True;Data Source={serverName};Update Isolation Level=2;Initial Catalog={databaseName}";
6991
break;
7092
}
7193
return connectionString;

AnalyzeInExcel/OdcHelper.cs

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
using System;
22
using System.IO;
3+
using System.Windows;
34

45
namespace AnalyzeInExcel
56
{
67
public static class OdcHelper
78
{
8-
public static void CreateOdcFile(string datasource, string database, string cube)
9+
public static string CreateOdcFile(string datasource, string database, string cube)
910
{
1011
string oledbConnectionString = ModelHelper.GetOleDbConnectionString(datasource, database);
1112
string odcHeader = @"
@@ -120,18 +121,44 @@ function init() {
120121
121122
";
122123

123-
var odcPath = OdcFilePath();
124+
var odcPath = GetOdcFilePath();
124125
File.WriteAllText(odcPath, odcHeader + string.Format(odcBody, oledbConnectionString, cube) + odcFooter);
125-
126+
return odcPath;
126127
}
127128

128-
public static string OdcFilePath()
129+
private static string GetOdcFilePath()
129130
{
130-
var myDocs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments, Environment.SpecialFolderOption.Create);
131-
var dsPath = Path.Combine(myDocs, "My Data Sources", "AnalyzeInExcel.odc");
131+
const string ODC_FILENAME = "AnalyzeInExcel.odc";
132+
const string MY_DATA_SOURCES = "My Data Sources"; // This is not localized - TODO find the localized version of this name
132133

133-
// ensure that the folder exists
134-
Directory.CreateDirectory(Path.GetDirectoryName(dsPath));
134+
var myDocs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments, Environment.SpecialFolderOption.Create);
135+
var dsPath = Path.Combine(myDocs, MY_DATA_SOURCES, ODC_FILENAME);
136+
137+
try
138+
{
139+
// ensure that the folder exists
140+
Directory.CreateDirectory(Path.GetDirectoryName(dsPath));
141+
}
142+
catch (Exception)
143+
{
144+
// If the folder is not available or accessible, try the file in MyDocuments
145+
dsPath = Path.Combine(
146+
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
147+
ODC_FILENAME);
148+
}
149+
150+
try
151+
{
152+
using (StreamWriter w = File.AppendText(dsPath))
153+
{
154+
// If the file can be opened this way, it should be writable
155+
}
156+
}
157+
catch ( Exception )
158+
{
159+
// If the previous attempt fails, the last resort is creating the file in the TEMP directory
160+
dsPath = Path.GetTempFileName().Replace(".tmp", "AnalyzeInExcel.odc");
161+
}
135162
return dsPath;
136163
}
137164
}

AnalyzeInExcel/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@
5151
// You can specify all the values or you can default the Build and Revision Numbers
5252
// by using the '*' as shown below:
5353
// [assembly: AssemblyVersion("1.0.*")]
54-
[assembly: AssemblyVersion("1.0.3.0")]
55-
[assembly: AssemblyFileVersion("1.0.3.0")]
54+
[assembly: AssemblyVersion("1.0.4.0")]
55+
[assembly: AssemblyFileVersion("1.0.4.0")]

ExternalToolsInstaller/ExternalToolConfiguration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace ExternalToolsInstaller
88
{
9+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Use names of external configuration")]
910
public class ExternalToolConfiguration
1011
{
1112
public string version { get; set; }

ExternalToolsInstaller/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.3.0")]
36-
[assembly: AssemblyFileVersion("1.0.3.0")]
35+
[assembly: AssemblyVersion("1.0.4.0")]
36+
[assembly: AssemblyFileVersion("1.0.4.0")]

SetupAnalyzeInExcel/SetupAnalyzeInExcel.vdproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,7 +1629,7 @@
16291629
"SharedLegacy" = "11:FALSE"
16301630
"PackageAs" = "3:1"
16311631
"Register" = "3:1"
1632-
"Exclude" = "11:FALSE"
1632+
"Exclude" = "11:TRUE"
16331633
"IsDependency" = "11:TRUE"
16341634
"IsolateTo" = "8:"
16351635
}
@@ -3420,15 +3420,15 @@
34203420
{
34213421
"Name" = "8:Microsoft Visual Studio"
34223422
"ProductName" = "8:Analyze in Excel for Power BI Desktop"
3423-
"ProductCode" = "8:{46AF827B-0E49-4907-92FC-C60096C08105}"
3424-
"PackageCode" = "8:{588D46CE-2E9A-45E4-BDBA-03AA560416EF}"
3423+
"ProductCode" = "8:{2862FE53-3704-4B41-80B0-693BFFC187F0}"
3424+
"PackageCode" = "8:{CEF1CAA5-4465-474B-A077-E2A7C7D6414C}"
34253425
"UpgradeCode" = "8:{FC2F9C00-CAD5-455E-BD9D-B1C607F4ABDA}"
34263426
"AspNetVersion" = "8:4.0.30319.0"
34273427
"RestartWWWService" = "11:FALSE"
34283428
"RemovePreviousVersions" = "11:TRUE"
34293429
"DetectNewerInstalledVersion" = "11:TRUE"
34303430
"InstallAllUsers" = "11:TRUE"
3431-
"ProductVersion" = "8:1.0.3"
3431+
"ProductVersion" = "8:1.0.4"
34323432
"Manufacturer" = "8:Sqlbi"
34333433
"ARPHELPTELEPHONE" = "8:"
34343434
"ARPHELPLINK" = "8:"
@@ -4116,7 +4116,7 @@
41164116
{
41174117
"{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_B8059F38185844FF9E7100633B552E00"
41184118
{
4119-
"SourcePath" = "8:..\\AnalyzeInExcel\\obj\\Debug\\AnalyzeInExcel.exe"
4119+
"SourcePath" = "8:..\\AnalyzeInExcel\\obj\\Release\\AnalyzeInExcel.exe"
41204120
"TargetName" = "8:"
41214121
"Tag" = "8:"
41224122
"Folder" = "8:_3C819D033B8E4ED29DA3C4B4E2E7B98C"
@@ -4144,7 +4144,7 @@
41444144
}
41454145
"{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_BE740B1BEB9D410F82DDE5AF811E1E7C"
41464146
{
4147-
"SourcePath" = "8:..\\ExternalToolsInstaller\\obj\\Debug\\ExternalToolsInstaller.dll"
4147+
"SourcePath" = "8:..\\ExternalToolsInstaller\\obj\\Release\\ExternalToolsInstaller.dll"
41484148
"TargetName" = "8:"
41494149
"Tag" = "8:"
41504150
"Folder" = "8:_3C819D033B8E4ED29DA3C4B4E2E7B98C"

0 commit comments

Comments
 (0)