Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception thrown while opening connection #7

Closed
BeigeBadger opened this issue Mar 25, 2019 · 1 comment
Closed

Exception thrown while opening connection #7

BeigeBadger opened this issue Mar 25, 2019 · 1 comment

Comments

@BeigeBadger
Copy link

Following this guide. This issue does not occur in version 15.3.1.

Version: 15.3.1.1

Error message: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "Microsoft.AnalysisServices.AdomdClient.XmlaSR.resources" was correctly embedded or linked into assembly "AdomdClientNetCore" at compile time, or that all the satellite assemblies required are loadable and fully signed.

Stacktrace:

   at System.Resources.ManifestBasedResourceGroveler.HandleResourceStreamMissing(String fileName)
   at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark& stackMark)
   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark)
   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
   at System.Resources.ResourceManager.GetString(String name, CultureInfo culture)
   at Microsoft.AnalysisServices.AdomdClient.XmlaSR.Keys.GetString(String key, Object arg0, Object arg1)
   at Microsoft.AnalysisServices.AdomdClient.XmlaSR.HttpStream_ASAzure_TechnicalDetailsText(String rootActivityId, String currentUtcDate)
   at Microsoft.AnalysisServices.AdomdClient.ASAzureUtility.GetExtendedErrorInfo(HttpWebResponse httpResponse)
   at Microsoft.AnalysisServices.AdomdClient.HttpStream.GetExtendedErrorInfo()
   at Microsoft.AnalysisServices.AdomdClient.CompressedStream.GetExtendedErrorInfo()
   at Microsoft.AnalysisServices.AdomdClient.XmlaReader.GetExtendedErrorInfo()
   at Microsoft.AnalysisServices.AdomdClient.XmlaClient.ReadXmlaError(XmlReader reader)
   at Microsoft.AnalysisServices.AdomdClient.XmlaClient.ReadFaultBody(XmlReader reader, XmlaMessageCollection xmlaMessages)
   at Microsoft.AnalysisServices.AdomdClient.XmlaClient.CheckForSoapFault(XmlReader reader, XmlaResult xmlaResult, Boolean throwIfError)
   at Microsoft.AnalysisServices.AdomdClient.XmlaClient.CheckForError(XmlReader reader, XmlaResult xmlaResult, Boolean throwIfError)
   at Microsoft.AnalysisServices.AdomdClient.XmlaClient.SendMessage(Boolean endReceivalIfException, Boolean readSession, Boolean readNamespaceCompatibility)
   at Microsoft.AnalysisServices.AdomdClient.XmlaClient.Discover(String requestType, String requestNamespace, ListDictionary properties, IDictionary restrictions, Boolean sendNamespacesCompatibility, IDictionary requestProperties)
   at Microsoft.AnalysisServices.AdomdClient.XmlaClient.Discover(String requestType, ListDictionary properties, IDictionary restrictions, Boolean sendNamespacesCompatibility)
   at Microsoft.AnalysisServices.AdomdClient.AdomdConnection.XmlaClientProvider.Microsoft.AnalysisServices.AdomdClient.AdomdConnection.IXmlaClientProviderEx.Discover(String requestType, IDictionary restrictions, InlineErrorHandlingType inlineErrorHandling, Boolean sendNamespaceCompatibility)
   at Microsoft.AnalysisServices.AdomdClient.AdomdConnection.ReadDataSourceInfo()
   at Microsoft.AnalysisServices.AdomdClient.AdomdConnection.ConnectToXMLA(Boolean createSession, Boolean isHTTP)
   at Microsoft.AnalysisServices.AdomdClient.AdomdConnection.Open()
   at NzBrokersWebPortal.DataAccess.ReportRepository.GetDataFromAzureAnalysisServices() in C:\Users\mastan\Documents\Git\nzbrokers-web-portal\NzBrokersWebPortal\DataAccess\ReportRepository.cs:line 190

Code:

private async Task GetDataFromAzureAnalysisServices()
		{
			//Grab the token
			//Get servername from Azure Analysis Service (Overview) resource 
			//Format: asazure://<region>.asazure.windows.net/<servername>
			string serverDomain = "australiasoutheast.asazure.windows.net";
			string databaseModel = "nzbrokersdevpilotv1";
			string serverName = $"asazure://{serverDomain}/{databaseModel}";
			string token = await GetAccessToken($"https://{serverDomain}");
			var connectionString = $"Provider=MSOLAP;Data Source={serverName};Initial Catalog={databaseModel};User ID=;Password={token};Persist Security Info=True;Impersonation Level=Impersonate";

			try
			{
				//read data from AAS
				using (AdomdConnection connection = new AdomdConnection(connectionString))
				{
					connection.Open();
					var mdX = @"EVALUATE (
					  TOPN (
						10,
						SUMMARIZECOLUMNS (
						  'Customer'[First Name],
						  'Customer'[Last Name]
						),
						'Customer'[Last Name],1
					  )
					)";

					using (AdomdCommand command = new AdomdCommand(mdX, connection))
					{
						var results = command.ExecuteReader();
						foreach (var result in results)
						{
							Console.WriteLine($"FirstName: {result[0]?.ToString()}; LastName: {result[1]?.ToString()}");
						}
					}
				}
			}
			catch (Exception ex)
			{
				Console.WriteLine(ex);
			}
		}

		private static async Task<string> GetAccessToken(string aasUrl)
		{
			var tenantId = "redacted";					// TODO: Move this into userSecrets
			var appId = "redacted";						// TODO: Move this into userSecrets
			var appSecret = "redacted";			// TODO: Move this into userSecrets
			string authorityUrl = $"https://login.microsoftonline.com/{tenantId}";

			var authContext = new AuthenticationContext(authorityUrl);

			// Config for OAuth client credentials 
			var clientCred = new ClientCredential(appId, appSecret);
			AuthenticationResult authenticationResult = await authContext.AcquireTokenAsync(aasUrl, clientCred);

			//get access token
			return authenticationResult.AccessToken;
		}
@BeigeBadger
Copy link
Author

I was providing the wrong value to Data Source. Works now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant