0
votes

want to run exe from asp.net on my server, is this possible?

I use this method:

    System.Diagnostics.Process process1 = new System.Diagnostics.Process();
    // Set the directory where the file resides

    process1.StartInfo.WorkingDirectory = @"D:\dev\Analyzer\bin\Release";
    // Set the filename name of the file you want to open

    process1.StartInfo.FileName = @"D:\dev\Analyzer\bin\Release\Analyzer.exe";
    process1.StartInfo.Arguments = "123";
    // Start the process

    process1.Start();

it works when i debug it, but when put my website on localhost then i have exception:

Login failed for user 'IIS APPPOOL\dq'

where dq is name of my website.

Stack:

System.Data.SqlClient.SqlException (0x80131904): Login failed for user 'IIS APPPOOL\dq'. at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject) at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) at System.Data.SqlClient.SqlConnection.Open() at System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionUser user) at System.Data.Linq.SqlClient.SqlProvider.get_IsSqlCe() at System.Data.Linq.SqlClient.SqlProvider.InitializeProviderMode() at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query) at System.Data.Linq.DataQuery`1.System.Collections.Generic.IEnumerable.GetEnumerator() at Analyzer.Program.Main(String[] args) in D:\dev\Analyzer\Program.cs:line 59

2
Please provide the full exception details. Saying an exception was thrown is useless without the details.Oded
What useraccount does the website use and does it have access to these files?Gluip
Also it requires certain .net permissions wich might not be granted on most hosts.Jan-Peter Vos
What line are you getting this exception on? It has nothing to do with the code you posted, unless this is thrown by your analyser.exe.Oded
And what it the exception? I am assuming that the TdsParser is choking on the SQL.Oded

2 Answers

2
votes

I am assuming here that the exception you are getting is an access violation one.

If that is the case, you need to ensure to either start the process with a UserName and Password for an account with enough privileges to run the executable (and access the directory it is in), or setup the application pool with such an account.


Update:

The stack trace points at a bad LINQ query, not Process.Start. What exactly is the exception? I can't tell from the trace.

What line is this throwing on?


Update 2:

Check your connection strings and SQL Server - the site account is failing to login to SQL Server. This has absolutely nothing to do with Process.Start or LINQ syntax.

Have you set the correct password? If you are using integrated security (SSPI=true), have you ensured that SQL Server has this login enabled?

1
votes

This approach is not recommended at all. On server, your ASP.NET website also runs as a process. Launching another process would require some extra permissions. Worker process is trying to launch analyzer.exe with its own user's (IIS APPPOOL\dq) account and is failing there. You would require to run your worker process with another account which will have enough permissions to launch another executable.

BTW, this will open up your surface area for threats. Not recommended at all.

Thanks Gaurav