First Step into ADOMD.Net - Cannot reference Microsoft.AnalysisServices - c#

Can someone help me out please, as google is not providing the answers.
I've got a SharePoint 2007 setup which uses SQL Server 2008 R2 SSAS OLAP cubes via some web parts.
As a C# developer, Sharepoint is a nightmare, so I decided I needed to try to get to grips with just C# and OLAP interaction. My cubes all exist, and are working, so all I needed to do was create a simple C# App to get it all straight in my mind.
I've downloaded Microsoft.AnalysisServices v10.0.0.0 and I can see it sitting happily in my GAC, but I can't add a reference from within my Visual Studio 2010 C# 4.0 project. It's just notappearing. I've tried setting the app to use 3.5, but still no joy.
Any clues?

Have you added the reference for Microsoft.AnalysisServices.AdomdClient.dll located in C:\Program Files\Microsoft.NET\ADOMD.NET\100

You could also use the nuget package manager. Type this in the console
Deprecated version (does not exist anymore):
install-package Microsoft.AnalysisServices.AdomdClient
New version:
Install-Package Microsoft.AnalysisServices.AdomdClient.retail.amd64

I think you need to reference the file directly, rather than through the GAC. It should be located in C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies

AdomdConnection steps
AdomdConnection con = new AdomdConnection("connectionstring"); // connect DB
con.Open();
AdomdCommand cmd = new AdomdCommand("MDX query", con); //query
AdomdDataReader reader = cmd.ExecuteReader(); //Execute query
while (reader.Read()) // read
{
Data dt = new Data(); // custom class
dt.Gender = reader[0].ToString();
dt.Eid = reader[1].ToString();
dt.salary = reader[2].ToString();
data.Add(dt);
}

Related

How to import old mdb-database into C# DataTable [duplicate]

This question already has answers here:
Proper way of getting a data from an Access Database
(4 answers)
Closed 1 year ago.
I got a very old mdb-database.
I want to load all tables from the database into a C# DataTable.
If possible the final tool should be stand-alone and don't need to install additional software.
Environment
.NET 5.0
Visual Studio 2019
Windows 10 - 64 bit
Office 365 - 32 bit
Questions:
How does the code for this looks like?
Which packages do I have to add/install?
Are there other dependencies?
Code:
string dbLocation = "DatabaseName.mdb";
string tableName = "TableName";
string connString = $"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={dbLocation}";
DataTable results = new DataTable();
using (OleDbConnection conn = new OleDbConnection(connString))
{
OleDbCommand cmd = new OleDbCommand($"SELECT * FROM {tableName}", conn);
conn.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
adapter.Fill(results);
}
Conditions:
In order to the Office-Version that is installed (32/64 bit) you have to install Microsoft Access Database Engine 2010/2016 Redistributable (for me it was 2010).
Most office installations are 32 bit.
Microsoft Access Database Engine 2010 Redistributable
Microsoft Access Database Engine 2016 Redistributable
If you choose the right version an still get an error trying to install in silent mode
accessdatabaseengine.exe /quiet
Add package System.Data.OleDb
Target plattform of the application has to be set to x86/x64 according to the other packages that are used
Still not solved:
Actually you need to have Microsoft Access Database Engine Redistributable installed. If there exist any other methode without this, please let me know.

Visual Studio Project Installer not installing all dll's

I have a C# exe, called 'start.exe' that is when run will check a SQL database and copy a file to a folder if certain criteria are met.
This works on most computers.
But on some computers when I try to run it I get the following error message.
System.invalidOperationException: The 'Microsoft.ACE.OLEDB.12.0' is not registered on the local machine
To fix this I created a setup project that should add the missing .dll.
I created the set up project, went to the applications folder, added the primary output of the project.
I then ran a batch build on all the files and copied the msi and setup .exe files to a problem computer and ran it.
It adds System.Net.Http.dll and 'start.exe' to the computer.
When I run the exe, it still gives me the same error.
I believe the message box comes from these lines of code.
try
{
using (var conn = new OleDbConnection(#"Provider =Microsoft.ACE.OLEDB.12.0;Data Source=" + CurFeSource + ";"))
{
conn.Open();
using (var cmdBE = new OleDbCommand("SELECT value FROM Tab1", conn))
{
OleDbDataReader rdrBE = cmdBE.ExecuteReader();
rdrBE.Read();
be_version = (rdrBE.GetString(0));
rdrBE.Close();
}
using (var cmdFE = new OleDbCommand("SELECT Col FROM Links", conn))
{
OleDbDataReader rdrFE = cmdFE.ExecuteReader();
rdrFE.Read();
fe_version = (rdrFE.GetString(0));
rdrFE.Close();
}
}
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
return false;
}
Edit:
As SQLGeorge said, I need to install Microsoft.ACE.OLEDB.12.0.
But how do I add it to a setup project.
The Microsoft.ACE.OLEDB.12.0 must be downloaded from Microsoft:
https://www.microsoft.com/en-US/download/details.aspx?id=13255
Excerpt From Microsoft:
This download will install a set of components that facilitate the transfer of data between existing Microsoft Office files such as Microsoft Office Access 2010 (*.mdb and .accdb) files and Microsoft Office Excel 2010 (.xls, *.xlsx, and *.xlsb) files to other data sources such as Microsoft SQL Server. Connectivity to existing text files is also supported. ODBC and OLEDB drivers are installed for application developers to use in developing their applications with connectivity to Office file formats.
As noted by Microsoft:
As a general replacement for Jet (If you need a general replacement for Jet you should use SQL Server Express Edition).

Why C# does not recognize Server() even after adding assembly "Microsoft.SqlServer.ConnectionInfo"

The type or namespace name 'Server' could not be found (are you missing a using directive or an assembly reference?)
string connetionString = #"connectionStirng";
SqlConnection conn = new SqlConnection(connetionString);
var server = new Server(new ServerConnection(conn));
added at the top
using Microsoft.SqlServer.Management.Common;
Still giving error.
Any help appricated.
Already checked:
Why i'm getting error for the Microsoft.SqlServer.Server namespace?
I can't add Microsoft.SqlServer.Management.Common to my ASP.NET MVC Application
Install this nuget package:
https://www.nuget.org/packages/Microsoft.SqlServer.SqlManagementObjects
Then add using directive:
using Microsoft.SqlServer.Management.Smo;
Now you can create Server object.
var server = new Server();
Installing SMO
Beginning with SQL Server 2017 SMO is distributed as the
Microsoft.SqlServer.SqlManagementObjects NuGet package to allow users
to develop applications with SMO.
This is a replacement for SharedManagementObjects.msi, which was
previously released as part of the SQL Feature Pack for each release
of SQL Server. Applications that use SMO should be updated to use the
NuGet package instead and will be responsible for ensuring the
binaries are installed with the application being developed.
https://learn.microsoft.com/en-us/sql/relational-databases/server-management-objects-smo/installing-smo?view=sql-server-2017
As suggested by Han, Please check the assembly reference path and make sure that the file is there at the referenced location. I had faced similar problem, this was working on the Development environment but error on test server. The reason was the SQL Server Management studio was not installed on the Test server. So i copied the required Assemblies from dev machine to bin folder of the application on test server and that worked.
Can you try adding a reference to:
Microsoft.SqlServer.dac.dll
If cant find the dll, then need to install SSDT (Sql Server Data Tools).

Failed to execute package SSIS using c#

I created SSIS package using integration service project in vs 2015.
My connection establishment is successful using Datasource. I can execute package using Execute Package Utility and Command line which is successful.
Please check below screens shots for the same.
I am facing problem while executing same package using c#. getting failed to execute package.
I have applied eventlistener, getting below error.
Please find below few screenshots for more information.
Code for reference:
Application app = new Application();
Package pkg = app.LoadPackage(#"C:\Project\Sample\Package1.dtsx", listener);
DTSExecResult results = pkg.Execute(null, null, listener, null, null);
In results object i got failure with given error.
As #Tab Alleman says you can run the package by calling a stored procedure sp_start_job from C# that starts SQL Agent JOB.
Here a piece of code that can be of help in this type of approach, after creating the SQL Agent JOB:
SqlConnection Conn = new SqlConnection(YOURCONNECTION);
SqlCommand ExecuteJob = new SqlCommand();
ExecuteJob.CommandType = CommandType.StoredProcedure;
ExecuteJob.CommandText = "msdb.dbo.sp_start_job";
ExecuteJob.Parameters.AddWithValue("#job_name", YOURJOBNAME")
ExecuteJob.Connection = Conn;
using (Conn)
{
Conn.Open();
using (ExecuteJob)
{
ExecuteJob.ExecuteNonQuery();
}
}
I hope this help.
Unfortunately your output does not show what the exact error message is. I have had problems in the past executing packages directly from C#.
One way around this is to create a SQL Agent job that executes the package, and then call a stored procedure from C# that starts the SQL Agent Job.

You are trying to access an older version of a SQL Server Compact Edition database

I am getting error when I am trying to open connection. My DB.sdf file is in my application folder
here i stored db.sdf
{
string ConnectionString= new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName + #"\APP_DATA\DB.sdf";
public int ExecuteNonQuery(string query){
int res = -1;
try
{
using (SqlCeConnection conn = new SqlCeConnection(ConnectionString))
{
SqlCeCommand command = new SqlCeCommand(query, conn);
command.CommandType = CommandType.Text;
conn.Open();
res = command.ExecuteNonQuery();
}
}
catch (Exception e)
{
new Logs().TraceProcessError(e.Message);
}
return res;
}
}
Error:
You are trying to access an older version of a SQL Server Compact
Edition database. If this is a SQL Server CE 1.0 or 2.0 database, run
upgrade.exe. If this is a SQL Server Compact Edition 3.0 or later
database, run Compact / Repair. [ Db version = 3505053,Requested
version = 3004180,File name = D:\DB.sdf ]"
and I am using SQL Server Compact 3.5., VS2010, SQLServer 2008R2.
please help.
thanks.
Can you please refer to the link below:
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/058357a2-e8a2-447e-82dc-df4466542855/trying-to-open-a-sql-compact-db-in-vb2005-created-it-in-vb2008?forum=sqlce
Hope it helps..!!
Make sure that you (1) know which version of SQL Server CE you database is, and (2) that you reference the appropriate System.Data.SqlServerCe.DLL from you project that matches that version of SQL CE.
Download SQL Server compact toolbox from here
https://sqlcetoolbox.codeplex.com/
Run it against your data base file and note down the version number (eg. 3.5)
Go into visual studio click on System.Data.SqlServerCe under resources and then click under the properties. In properties note down the version number (eg. 3.0)
If the the library version number is older. Download the SQL Server Compact installer and run.
http://www.microsoft.com/en-IE/download/details.aspx?id=12264
Once installed. Delete the references to System.Data.SqlServerCe and System.Data.SqlClient from your project and add their equivalent 3.5 versions. Found on my system at.
C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v3.5\Devices\System.Data.SqlServerCe.dll
and
C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v3.5\Devices\Client\System.Data.SqlClient.dll
Clean and then rebuild. Like I mentioned in the comment, this undid itself at some point on VS 2008 so if you get the error again double check the path is going to the above.

Categories

Resources