Ho to connect to Power BI dataset using ADOMD.Net - c#

I am using Microsoft.AnalysisServices.AdomdClient.dll, v13.0.0.0 to to access a Power BI data set from C# code.
Have been experimenting with various connection strings but always get exceptions...
var connectionString = #"Provider=MSOLAP.7;Integrated Security=;Identity Provider=AAD;Data Source=https://analysis.windows.net/powerbi/api;Initial Catalog=XXXX-XXXX-GUID;Location=https://wabi-us-north-central-redirect.analysis.windows.net/xmla?vs=sobe_wowvirtualserver&db=XXX-XXX-GUID;MDX Compatibility= 1; MDX Missing Member Mode= Error; Safety Options= 2; Update Isolation Level= 2;User ID=my#workemail.com;Password=my_pswd;";
var conn = new AdomdConnection(connectionString);
conn.Open(); //throws here
The connection string above produces error
"The connection either timed out or was lost."
This string is based on the .odc file that I downloaded from Power BI, and it works fine from Excel - data is loaded into pivot table, etc. (Excel uses COM driver I guess?)
If I set Integrated Security = SSPI or Basic, the client throws another error saying that neither of them can be used with HTTP.
What is missing in my code? I am looking for a working sample of a connection string for Power BI.
Thanks!
UPDATE:
There is an inner exception for the connection string above:
"The remote name could not be resolved: 'analysis.windows.net'"
This url is what Power BI puts into odc file when I click on ANALYSE IN EXCEL. What url should I use to connect to data from .Net code?

I discovered that to connect to power bi i needed version 19.9.0 , connection will prompt for username and password.
https://www.nuget.org/packages/Microsoft.AnalysisServices.AdomdClient.retail.amd64
https://www.nuget.org/packages/Microsoft.AnalysisServices.retail.amd64
connectionString= $"Provider=MSOLAP;Data Source=powerbi://api.powerbi.com/v1.0/myorg/{workspacename};";

I used the NuGet Package "Microsoft.AnalysisServices.AdomdClient.NetCore.retail.amd64" in my Project with the following Connectionstring:
Provider=MSOLAP;Data Source=powerbi://api.powerbi.com/v1.0/myorg/{WorkspaceName};Initial Catalog=Sales;User ID=app:{ApplicationId}#{TenantID};Password={Application Secret};
More Details here

Related

Unable connect to MySQL from C# but possible from other apps

I wanted to change MySQL server in my C# app. The app is run in my company and both - old and new MySQL servers are only accessible from the intranet. The problem is I can connect from HeidiSQL software and from python code but not from C#...
I have tried all possible solutions what I found, for ex. disabling firewall, using different packages from NuGet, modifying connection string, I created new console project only to paste various MySQL connection code - always with same error
Message: Unable to connect to any of the specified MySQL hosts.
Source: MySql.Data
Number: 1042
I', using .net Framework 4.5.2 (4.6.1 in my test project) and MySQL Server is '5.6.44-log - MySQL Community Server (GPL)'
One of C# connection code example that I have tested that is NOT working
using MySql.Data.MySqlClient;
public static MySqlConnection DB_connection;
DB_connection = new MySqlConnection(#"Server=MyIP;Database=myDB;Uid=my_user;Pwd=pass;");
try
{
DB_connection.Open();
isConn = true;
}
catch (...)
Working python code run from the same PC
import pymysql
import pprint
connection = pymysql.connect(host='MyIP',
user='my_user',
password='pass',
db='myDB')
try:
with connection.cursor() as cursor:
sql = "select * from table;"
cursor.execute(sql)
# connection.commit()
result = cursor.fetchall()
pprint.pprint(result)
finally:
connection.close()
Don't see anything wrong with your posted connection string but in case your's is a replicated scenario (I mean DB replication exists) then you will have to specify the replicated server IP/hostname as well like
Server=serverAddress1, serverAddress2, serverAddress3;Database=myDataBase;
Uid=myUsername;Pwd=myPassword;

Cause Of SQL Connection Error

Within my ASP.NET C# WebForms app I am attempting to connect to my SQL Database.
Upon connection I get the error:
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
I've attempted to google what this error means but the results do not clearly explain whats wrong. Can you tell me what exactly is wrong (its not finding the database file, it found the file but the database file is incorrect version, etc.)?
These are the steps I have performed:
Create a local database using VS2013. The file is located in 'MyProjectPath\App_Data\Pages.mdf'
The database is populated with a table and rows
I have connected to the server by 'Server Explorer->Connect To Server->Type in my computer username'. No errors appear
In the Server Explorer I have tested my connection to the database and it succeeded.
Connection is 'Microsoft SQL Server Database File (SqlClient)'
I have copied the 'ConnectionString' to web.config. One important thing is that the string contains quotation marks and I have to remove these.
Do I need to start an external application like SQL Server Management Studio or something?
Connection String:
Data Source=(LocalDB)\v11.0;AttachDbFilename="C:\VERY_LONG_PATH_THAT_HAS_SPACES\App_Data\Pages.mdf";Integrated Security=True
I remove the quotations:
<connectionStrings>
<add name="MySQLConnStr" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\VERY_LONG_PATH_THAT_HAS_SPACES\App_Data\Pages.mdf;Integrated Security=True"/>
</connectionStrings>
// My simple connection code where the runtime error occurs
try
{
using (OdbcConnection connection = new OdbcConnection(ConfigurationManager.ConnectionStrings["MySQLConnStr"].ConnectionString))
{
// do stuff
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
Hi to make ODBC connection you need to have driver installed. You can make sql connection and this should work..
// Change your simple connection code to
try
{
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["MySQLConnStr"].ConnectionString);
connection.open();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
Try one by one below three solutions, it will help you to solve your problem.
You need to configure DSN in Administration Tools => ODBC, When install driver choose for all users instead current user
Try to look on your server for the ODBC Data Source Administrator that can be found in Control Panel --> Administrative Tools --> Data Sources (ODBC). (On 64 bit Windows systems, you'll have to explicitly call c:\windows\syswow64\odbcad32.exe ) and add the driver to the System DSN tab.
If the ODBC driver was not 64 bit, Try to compile your application as an x86 process and it will work.

oracle connection string with SID in c#

Hi I have to connect to an Oracle Database( about which I know a little) using a windows application.
The windows application will not necessarily be in the same system.
I just needed the connection string.
So I Used Add connection functionality in Visual Studio 2014 to test the connection and get the string.
eedb is the SID which i read in stackoverflow question
Now using above, i was able to connect to the database using this functionality and even in my visual studio server explorer all the tables of the oracle database were showing but I needed to use the connection string in the windows application.
So I used following string:
DATA SOURCE=172.31.8.21:1521/eedb;USER ID=PDB_E_GND_R
I added password too to this string as
DATA SOURCE=172.31.8.21:1521/eedb;USER ID=PDB_E_GND_R;PASSWORD=123
when i run the application i get error.
System.Data.OracleClient.OracleException: ORA-01017: invalid username/password; logon denied.
So :
Why I am getting this error. Now some may mark this question as duplicate and even point out the answer can be found in issue stackoverflow question
Coz if this was the case I would have been unable to establish connection through add connection functionality of Visual Studio at all.
Please note: I added the reference: Oracle.DataAccess
And also for a programmer like me who has very little knowledge regarding the oracle.
How I can know which connection string I have to use for a particular oracle db.
Try the following connection string EZ connect does not seem to be so EZ
data source=(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 172.31.8.21)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = eedb)));USER ID=PDB_E_GND_R;PASSWORD=123

Getting 12154: TNS:could not resolve the connect identifier specified error with .NET

I've written this simple connection in my code:
OracleConnection con = new OracleConnection("Data Source=ORCL;User
ID=agapus;Password=agap");
con.Open();
Then I run my application pressing F5 and I get the above error. This error occurs no matter if it's just a simple console app or an ASP.NET web site. I've tried both Oracle.DataAccess and the old windows oracle API. I've tried several Oracle services, all with no luck.
The environment where I'm testing this connection is a Windows Server 2008R2. I can easily connect to any database using SQLPlus or TOAD. I've tried explicitly specifying the location of the TNS_NAMES.ORA file, doesn't work either.
The only thing that works is when I specify the full path in the connection string. So if I change the above code into the below one, it'll work:
string conString = "user id=agapus;password=agap;data source=(DESCRIPTION=(ADDRESS=
(PROTOCOL=tcp)(HOST=172.16.0.121)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL)))";
ID=agapus;Password=agap");
OracleConnection con = new OracleConnection(conString);
con.Open();
If you look in your sqlnet.ora file, I believe that you will find that the default domain is set to .world .
That would make the correct name of your connection ORCL.world .
You may also have .world on the end of your connection name in TNSNAMES.ora, and nothing for the default domain.
What do you get when you run tnsping?

Connecting to a Shared Data Source at Runtime

I am writing a report builder program that is similar to Microsoft's Report Builder but to be hosted on an existing web application. It should be able to:
connect to a report server (SSRS2008) and a pre-configured shared data source;
let the user design RDLCs; and,
dynamically generate reports without the need for Visual Studio.
Basically, it's a stand-alone albeit proprietary report generation tool.
The users need not be report writers but do they have an understanding on how data is correlated in the database. (There are existing relationships between tables.) For some reason, they cannot or should not have access to the SSRS site to build reports from there (i.e. use Microsoft's Report Builder tool). They have to use the tool I am creating.
I'm very much done with the last two bullets. The first one is giving me the issue: I'm relatively new to this and probably it's not trivial. How can I connect to an SSRS2008 data source at runtime?
In my web.config, I added an entry to the connectionStrings like so:
<add name="ReportingSDS" connectionString="Server=http://myReportingServer;datasource=http://myReportingServer/reportserver/models/myReportModel.smdl;Integrated Security=True"/>
which is based on the prescribed format.
And I ran into a brick wall after this:
using (var conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["ReportingSDS"].ConnectionString))
{
conn.Open();
// what's next?
}
The error I'm getting is:
A network-related or instance-specific error occurred while
establishing a connection to SQL Server. The server was not found or
was not accessible. Verify that the instance name is correct and that
SQL Server is configured to allow remote connections. (provider: Named
Pipes Provider, error: 40 - Could not open a connection to SQL Server)
My goal is to retrieve that DataSet and plug it into this snippet:
using (var memRDLC = new MemoryStream(Encoding.ASCII.GetBytes(myRdlcXml)))
{
// Bind the rdl memory stream and data set to reportviewer
rptViewer.ProcessingMode = ProcessingMode.Local;
LocalReport r = rptViewer.LocalReport;
r.LoadReportDefinition(memRDLC);
foreach (DataTable dataTable in reportEngine.DataTables)
{
r.DataSources.Add(new ReportDataSource(
dataTable.TableName + "_Table", dataTable));
}
r.Refresh();
}

Categories