How to find out that SSIS installed in SQL Server using C#? - c#

I'm writing a Windows Form application using C#. I use
ssisServer = new IntegrationServices(ssisConnection);
to run and work with SSIS packages but before running the package I wanted to make sure the user runs the application in the correct system and SQL Server has the SSIS on it's SQL Server.
How can I find whether SSIS is installed on the server or not in C#?

Check if the SQL Server Integration Services service is running on the server your connecting to.
SQL Server Service Name
SQL 2008 MsDtsServer100
SQL 2012 MsDtsServer110
SQL 2014 MsDtsServer120
SQL 2016 MsDtsServer130
SQL 2017 MsDtsServer140
SQL 2019 MsDtsServer150
The name of the service will depend on what version of SQL Server you are connecting to. If the server was SQL Server 2019 then it would be MsDtsServer150 for example. You could simply check if the service exists and is running.
Add System.ServiceProcess to your project references (It's on the .NET tab).
using System.ServiceProcess;
ServiceController sc = new ServiceController("MsDtsServer150");
switch (sc.Status)
{
case ServiceControllerStatus.Running:
return "Running";
case ServiceControllerStatus.Stopped:
return "Stopped";
case ServiceControllerStatus.Paused:
return "Paused";
case ServiceControllerStatus.StopPending:
return "Stopping";
case ServiceControllerStatus.StartPending:
return "Starting";
default:
return "Status Changing";
}

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;

System cannot find file while connecting database in nhibernate

I am using fluent nhibernate since long. Its working fine until I updated my database. Prior I was using SQL Server 2012, and updated it to 2016. When try to connect database in application, it throws an error:
The system cannot find the file specified.
when it tried to connect. My connecting function is as below
Fluently.Configure().Database(MsSqlConfiguration.MsSql2005.ShowSql().ConnectionString(x=> x.FromConnectionStringWithKey("imConnectionString2"))).Mappings(m=> m.FluentMappings.AddFromAssemblyOf<MapUsers>()).BuildSessionFactory();
This was working fine before database update. I change MsSql2005 it to MsSql2012, but same result.
Do I have to do anything in Fluent Nhibernate side or configuration?
Any assistance please
There is a major change in the client connectivity for SQL Server 2016.
This change is due to sql client is becoming support windows and other O.S like Linux.
install Microsoft ODBC Driver 13 for SQL Server - Windows
https://www.microsoft.com/en-us/download/details.aspx?id=50420
review: Installing SQL Server Native Client
SQL Server Native Client (SNAC) is not supported beyond SQL Server 2012. Avoid using SNAC in new development work, and plan to modify applications that currently use it. The Microsoft ODBC Driver for SQL Server provides native connectivity from Windows to Microsoft SQL Server
Before configuring Nhibernate, be sure that you can connect with SQL server 2016 by using sqlcmd tool (for server 2016- download it)
Update:
When you install the driver named msodbcsql.msi, it's really the same driver of sql 2012 client.
I installed the driver in windows 7 (32 bit), using the library FluentNHibernate v 2.0.3 and connecting to SQL server 2016 and running successfully the following code:
class FluentNHibernateTest
{
private static ISessionFactory CreateSessionFactory()
{
//also MsSqlConfiguration.MsSql2005 is working
return Fluently.Configure()
.Database(
MsSqlConfiguration.MsSql2012.ShowSql()
.ConnectionString(x => x.FromConnectionStringWithKey("test16")))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Program>())
.BuildSessionFactory();
}
public static string GetSqlVersion()
{
string sql = "select ##version version";
var sessionFactory = CreateSessionFactory();
using (var session = sessionFactory.OpenSession())
{
var query = session.CreateSQLQuery(sql);
var result = query.UniqueResult();
Console.WriteLine(result);
return result.ToString();
}
}
}
Output result:
FluentNHibernateTest.GetSqlVersion();
Microsoft SQL Server 2016 (RTM-CU1) (KB3164674) - 13.0.2149.0 (X64)
Jul 11 2016 22:05:22
.......

replacing data access strategy from SQL Server to Access MDB file in C#

I created a small accounting application a while back. It uses SQL Server 2008 as backend data store. Now I realize that SQL Server is too much for such a
small program PLUS it is not very much portable. I mean I want to have this application on my USB stick for easy access anywhere, and SQL Server will not be
available everywhere. So now I want to replace the data store from SQL Server to something portable i.e. MS Access MDB file.
1- Is it a good option or should I use SQL Server express edition?
2- I don't have experience using SQL Express edition. If I use it, would it be needed on any machine where I intend to run my application?
2- What changes should I make in the code to make it compatioble with MDF files (or SQL Express)?
As I said it is quite simple program, it uses connected model to fetch and insert data currently. For example
void bindGrid()
{
try
{
using (SqlConnection con = new SqlConnection(ConnectionString))
{
DataSet set = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
SqlCommand selectCommand = new SqlCommand("SELECT * FROM Categories ORDER BY name", con);
da.SelectCommand = selectCommand;
da.Fill(set);
this.grdCategories.DataSource = set.Tables[0];
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Rather than using Access, I would use LocalDB. It should require very few if any changes to your code other than the connection string.
http://blogs.msdn.com/b/sqlexpress/archive/2011/07/12/introducing-localdb-a-better-sql-express.aspx
LocalDB is created specifically for developers. It is very easy to install and requires no management, yet it offers the same T-SQL language, programming surface and client-side providers as the regular SQL Server Express. In effect the developers that target SQL Server no longer have to install and manage a full instance of SQL Server Express on their laptops and other development machines. Moreover, if the simplicity (and limitations) of LocalDB fit the needs of the target application environment, developers can continue using it in production, as LocalDB makes a pretty good embedded database too.
I would recommend SQL CE for small projects.
LocalDB vs SQL Server Compact
There are significant differences between LocalDB and SQL Server Compact:
Execution mode: SQL Server Compact is an in-proc DLL, while LocalDB runs as a separate process.
Disk usage: all SQL Server Compact binaries amount to some 4MBs, while LocalDB installation takes 140MBs.
Features: SQL Server Compact offers core RDBMS functionality like querying, while LocalDB provides a much richer set of features, including Stored Procedures, Geometry and Geography data types, etc.

Enable remote connections to sql express with a script

I am deploying an application with sql server express 2008. In the prerequisites section of my application I have included:
As a result when a user installs my application it will install sql express as well.
Then I will be able to connect to that database engine as:
try
{
// database should be in the same network
SqlConnection conn =
new SqlConnection(#"Data Source=.\sqlexpress; Integrated Security=True");
conn.Open();
MessageBox.Show("Connection succesfull");
}
catch
{
MessageBox.Show("Unable to connect");
}
Now when I install a different application(client version) I will like to be able to connect to that database engine. I managed to connect to it by doing something like:
try
{
SqlConnection conn =
new SqlConnection(#"Data Source=192.168.0.120\sqlexpress,22559; USER=sa; PASSWORD=*********");
conn.Open();
MessageBox.Show("Connection succesfull");
}
catch
{
MessageBox.Show("Unable to connect");
}
In order for that code to work I had to do the following:
So my question is:
How could I configure this with code? When I deploy my application I want my application to install sql express like it does but I also whant to enable tcp/IP connections, enable some ports and lastly create a password for the account "SA" because I am not able to connect to the database remotly if the sa account does not have a password.
Or maybe I am asking to much and I am doing the wrong thing. perhaps I should do all this just for the database that I am planing on deploying not the database engine. whatever is easier. I have had a hard time deploying this maybe it will be eassier to deoploy a local database along with a wcf service in order to create CRUD operations on the local database remotely.
EIDT
I found this 3 links that claim on doing something similar and I still cannot make it work.
1) http://support.microsoft.com/kb/839980
2) http://social.msdn.microsoft.com/Forums/en-US/sqlexpress/thread/c7d3c3af-2b1e-4273-afe9-0669dcb7bd02/
3) http://www.sql-questions.com/microsoft/SQL-Server/34211977/can-not-connect-to-sql-2008-express-on-same-lan.aspx
downloaded sql server express 2008 (SQLEXPR32_x86_ENU.exe) and place it in the root of my c drive. then I install it with the following parameters:
C:\SQLEXPR32_x86_ENU.exe /q /hideconsole /action=Install /features=SQL /instancename=SQLEXPRESS /enableranu=1 /sqlsvcaccount="NT Authority\Network Service" /AddCurrentUserAsSqlAdmin /skiprules=RebootRequiredCheck /TCPENABLED=1
I add /TCPENABLED=1 in order to enable TCP/IP
I suggest you to create modified bootstrapper package to install Sql Server 2005 Express with customzation.
As an alternative, you can also use a custom action in your installer to change the targeted server using SMO.
Something like this:
Server server = new Server( "ServerName\\InstanceName" );
server.ConnectionContext.Connect();
server.Settings.LoginMode = ServerLoginMode.Mixed;
server.Settings.Alter();
We use SMO object to create user login and associate user to our created application database.. even run sql script to create database if database is not available..
Refer these links:
Configuring SQL Express During Installation
Configuring SQL Server when included as a requirement
Note: Create your sql server connection string settings in App.config file rather than putting hardcore in code.. this will help you customize application first run customization e.g. database creation.
These might be of some help, I've had it on my todo list for a while for the computers I have to setup for my app to run with Sql Server 2008 Express. It's basically a way to setup a script that the SQL08exp installer will read and automate a lot of the setup according to what you set in the script.
http://digitalformula.net/articles/how-to-perform-an-unattended-installation-of-sql-server-2008-express/
http://blogesh.wordpress.com/2008/09/23/silent-install-of-sql-server-2008/

ListChildren SQL Reporting Service

I'm trying to get a list of available reports via the webservice for SQL Reporting Services 2005 express edition. Each time I try to call the ListChildren method I get an insuffient permission exception. The code is:
ReportingService2005SoapClient rService = new ReportingService2005SoapClient();
CatalogItem[] cItems = null;
rService.ListChildren("/", false, out cItems);
I added the ASP.net (iusr) account into the local admin group on the PC and still get the exception.
Is this method supported in the express edition?
Mark
The local admin group is not a part of SQL Server Administrators in SQL 2008 and I believe the same is true for SQL 2005 as well.
You can run the web service under a different domain account that has the priviledges, or in your SQL Reporting Services, add the Computer\ASPNET account as a user.

Categories