vendredi 17 juin 2016

Error when trying to connect to SQL Server from program on remote computer

I am trying to set up a system for employees to use in the office so they can run certain programs from a website.

They will be able to login and go to a reports page an click a button to run a reports program on the utility server. The program will connect to SQL Server to get the login information and then login to another site and programmatically create the reports and download them.

I have the website trying to run the program but it is terminated due to an unhandled exception. here is the stack trace from the error in the event viewer.

Application: Trending Reports.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Data.SqlClient.SqlException

Stack: at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(System.Data.Common.DbConnection, System.Data.ProviderBase.DbConnectionFactory, System.Threading.Tasks.TaskCompletionSource1<System.Data.ProviderBase.DbConnectionInternal>, System.Data.Common.DbConnectionOptions) at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(System.Data.Common.DbConnection, System.Data.ProviderBase.DbConnectionFactory, System.Threading.Tasks.TaskCompletionSource1, System.Data.Common.DbConnectionOptions) at System.Data.SqlClient.SqlConnection.TryOpenInner(System.Threading.Tasks.TaskCompletionSource1<System.Data.ProviderBase.DbConnectionInternal>) at System.Data.SqlClient.SqlConnection.TryOpen(System.Threading.Tasks.TaskCompletionSource1) at System.Data.SqlClient.SqlConnection.Open() at Trending_Reports.Program.Main(System.String[])

Here is the code I am using to start the program.

var processToRun = new[] { @"D:\test\Trending Reports.exe" };

var connection = new ConnectionOptions();
connection.Impersonation = System.Management.ImpersonationLevel.Impersonate;
connection.Username = "Username";
connection.Password = "password";

var wmiScope = new ManagementScope(String.Format("\\\\{0}\\root\\cimv2", "Server"), connection);

var wmiProcess = new ManagementClass(wmiScope, new ManagementPath("Win32_Process"), new ObjectGetOptions());
wmiProcess.InvokeMethod("Create", processToRun);

The program itself is using multi-threading. Could this be causing the issue? Or could it be a user issue to where its not using my user profile on the remote computer?

Aucun commentaire:

Enregistrer un commentaire