Transaction not connected when the app is called from a website - asp.net

I have a PowerBuilder.net console application that uses SQLNCLI10 to connect a SQL Server 2008 R2. This applications needs to be executed from a ASP.NET MVC website hosted in the same server, and its output readed.
This is the code for executing the application on the MVC:
var proc = new System.Diagnostics.Process
{
StartInfo = new System.Diagnostics.ProcessStartInfo
{
FileName = ConfigurationManager.AppSettings["PB_EXE"],
Arguments = Credentials.ClientId + " " + reference,
UseShellExecute = false,
RedirectStandardOutput = true,
WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden
}
};
When the application is executed from the MVC, the PBTransaction objects returns the generic "Transaction not connected" sql error.
The thing is, the application runs well with a .bat that call the executable with parameters. Even more, a simple WinForms using the same code above, gets the transaction connected successfully.
I have alredy tried setting the ApplicationPool of the website to the administrator of the server, with the same results.

What I'd check first to solve connectivity issues on a PB.NET console application.
Putting some logging into the console application and examine the Transaction object immediately before and after attempting the connection. It will likely provide necessary information to identify the culprit.
Make sure PowerBuilder database connectivity run-time libraries (e.g. PBORA010.DLL) are installed on the server and accessible to the role running the application.
If the connection uses ODBC/JDBC make sure any DSNs needed on server are accessible to the console application.

Related

SignalR SQL backplane not starting in Pre-Production

After 3 days, this problem's doin' my head in.
SignalR is not creating its backplane SQL schema and tables in my pre-prod environment containing a single SQL server + load balanced web servers.
I've checked
WebSockets are installed in IIS
DB access allows table and schema
creation
.Net 4.5 is installed and is being used
Recommended updates are
installed
The steps listed here are complete (with the exception of doing the deployment from Visual Studio - I use MSBUILD to package and then use WebDeploy)
I've piggy backed the SignalR tracing. Only my trace entries are written - nothing from SignalR.
Everything works (including tracing) in my development environment if I build in Release mode.
Here's my tracing-enhanced start-up process
//Step 1: Check tracing works
var trace = GlobalHost.TraceManager["TestTrace"];
trace.TraceInformation("Preparing to start SignalR");
//Step 2: Check DB access rights
var connectionString = ConfigurationManager.ConnectionStrings["SignalR"].ConnectionString;
var schema = Guid.NewGuid().ToString("N");
using (var sqlConn = new System.Data.SqlClient.SqlConnection(connectionString))
{
using (var sqlCmd = new System.Data.SqlClient.SqlCommand())
{
sqlConn.Open();
sqlCmd.Connection = sqlConn;
sqlCmd.CommandText = String.Format("CREATE SCHEMA [{0}]", schema);
sqlCmd.ExecuteNonQuery();
sqlCmd.CommandText = String.Format("SELECT '{0}' AS [Value] INTO [{1}].[ConnectionString]", connectionString, schema);
sqlCmd.ExecuteNonQuery();
}
}
//Step 3: Initialise SignalR
GlobalHost.DependencyResolver.UseSqlServer(connectionString);
app.MapSignalR(); //This is meant to trigger lots of logging.
//Step 4: Confirm we've successfully passed SignalR start-up
trace.TraceInformation("Finished starting SignalR");
Any help would be great. Cheers.
Problem wasn't in the server-side SignalR but in the client-side JavaScript's start-up routine aborting before connecting to the SignalR Hub.
It seems that SignalR doesn't start logging until the first connection is made.
For some reason (as yet unidentified) the SignalR start-up routine was completing in the development environment and aborting in the pre-production code. A possible cause is a different sequence of start-up events when using compressed JavaScript.

Difference between starting process from Console applciation and ASP.NET application

I have a Web API application that needs to run a Python script which in turn runs a Perl script:) does some otehr stuff and get the output results from it.
The way I do this is with starting a Process:
var start = new ProcessStartInfo()
{
FileName = _pythonPath, //#"C:\Python27\python.exe",
Arguments = arguments, //#"D:\apps\scripts\Process.py
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true
};
using (Process process = Process.Start(start))
{
using (StreamReader reader = process.StandardOutput)
{
var result = reader.ReadToEnd();
var err = process.StandardError.ReadToEnd();
process.WaitForExit();
return result;
}
}
The script inside tries to connect to Perforce server using P4 Python API and then Perl script call a P4 command as well. When running this code from Console application, everything goes fine. The program automatically gets the Perforce settings (I've got a P4V client with all the settings specified). But when running from ASP.NET Web API, it doesn't get the settigns and says that it cannot conenct to perforce:1666 server (I guess this is the standard value when no settign specified).
I do understand that not so many people use Perforce, especially in such way and can help here, but would like to know what is the difference between running this script from Console app and Web API app that mich cause this different behaviour.
One of the most obvious differences between running code from a console application and running code in IIS* is that, usually, the two pieces of code will be running under different user accounts.
Frequently, if you're experiencing issues where code works in one of those situations and not the other, it's a permissions or a per-user-settings issue. You can verify whether this is the case by either running the console application under the same user account that is configured for the appropriate IIS application pool, or vice verse, configure the application pool to use your own user account, and then see whether the problem persists.
If you've confirmed that it's a permissions issue and/or per-user-settings, then you need to decide how you want to fix it. I'd usually recommend not running IIS application pools under your own user account - if you cannot seem to get the correct settings configured for the existing application pool user, I'd usually recommend creating a separate user account (either locally on the machine or as part of your domain, depending on what's required) and giving it just the permissions/settings that it requires to do the job.
*IIS Express being the exception here because it doesn't do application pools and the code does end up running under your own user account.

SSAS Error The MyCube either does not exist or has not been processed when attempting to query through ASP.NET

I have a cube, which has been processed, works from the BID environment, and I can run my MDX query in both SSEM, and the BID env. I've created a role that contains the proper accounts/permissions, processed, and deployed the cube, re-processed it in SSEM, etc. Now I'm trying to connect, and extract the data using ASP.NET 4.0, but I'm getting this error:
The MyCube either does not exist or has not been processed
Here's my code:
String connectionString = "Provider=MSOLAP.3; Data Source=myhost;Initial Catalog=myCatalog; User ID=myaccount; Password=myamazinglysecurepassword;";
String mdxSQL = " my MDX, which was taken directly from BID env. cube in design mode";
AdomdConnection connection = new AdomdConnection(connectionString);
connection.Open();
AdomdCommand cmd = new AdomdCommand(mdxSQL, connection);
CellSet cst = cmd.ExecuteCellSet();
...etc
Note: we are not using MSMDPUMP.dll to connect, we'd like to avoid that.
Any Ideas?
A couple things to consider. How are users authenticating to your web app? What account is your application pool running as?
If you're using Integrated Windows in ASP.NET you may be getting a double-hop issue if IIS and SSAS on different servers. This would require you to set up Kerberos and trusted delegation SPN's between your application and the OLAP service.
See (SSAS and IIS):
http://msdn.microsoft.com/en-us/library/dn194199.aspx
http://technet.microsoft.com/en-us/library/dd632778.aspx
Otherwise there may be an issue with the account your application pool is running under. I see in your connection string you have a specific account - so I presume you are trying to connect as one account rather than delegating user credentials to OLAP. The process running w3wp.exe is the identity which will attempt to connect to SSAS. If your application pool is not runnning as a domain account is may not be able to authenticate to SSAS.

Sync creating multiple subscription sqlcereplication

I am currently developing a bridge between a database and a sql server database android (sqlite).
To do this, I use a web service and filtered replications with sqlce databases stored on a server IIS 7. To develop this, I used IIS Express on my pc. Everything works fine on my pc but when deployed, replicated databases create a new subscription for each synchronization (while on IIS Express sync works without creating a new subscription), no exceptions are thrown, nothing.
I don't understand why IIS 7 or IIS Express works in a different way to sync databases.
An idea of ​​the reason of the problem?
I use Sql replication ce 3.5 sp2, Sql server 2008 R2 as mother database, IIS7.
I tried to :
-Replicate motherdatabase with a little software on the webserver, it works.
-Use "SqlCeReplication.loadproperties" to find my sqlce database parameters to avoid the creation of the new subscription, it doesn't work.
Other details :
-When it is not syncing for the first time, webservices don't do "repl.AddSubscription(AddOption.CreateDatabase)", I already check that.
Here is the code used to sync :
' Define the server, publication, and database names.
Dim repl As SqlCeReplication = Nothing
Try
repl = New SqlCeReplication
repl.Publisher = PublisherName
repl.PublisherLogin = login
repl.PublisherPassword = password
repl.PublisherSecurityMode = SecurityType.DBAuthentication
repl.PublisherDatabase = My.Settings.DBName
repl.Publication = PublicationName
repl.InternetUrl = "https://iis.mydomain.com:444/sql/sqlcesa35.dll"
repl.InternetLogin = "sync"
repl.InternetPassword = "dfssd"
repl.Subscriber = "MobileApp - " & login
repl.SubscriberConnectionString = "Data Source=" & My.Settings.folderDB + "\" + subscriptionName + ".sdf"
If Not File.Exists(My.Settings.dossierBDD + "\" + subscriptionName + ".sdf") Then
repl.AddSubscription(AddOption.CreateDatabase)
End If
repl.Synchronize()
Catch err As SqlCeException
Finally
repl.Dispose()
repl = Nothing
End Try
Thanks in advance
I found myself the answer...
I don't really know why but if you want to do merge replication on sqlce, you will need to let the IIS website "Load the user profile" (on the application pool), otherwise subscription are created each time...

Run PowerShell script from ASP.NET

I have been trying out running a PowerShell script from asp.net with no success for a few days already.
The C# is:
using (var process = new Process())
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = #"powershell.exe";
startInfo.Arguments = "arguments that call the script here";
startInfo.RedirectStandardOutput = false;
startInfo.RedirectStandardError = false;
startInfo.UseShellExecute = true;
startInfo.CreateNoWindow = true;
process.StartInfo = startInfo;
process.Start();
}
The PowerShell script it calls contains the ff:
robocopy "\\network-server\location" "C:\localfolder" "testmovefile.txt"
Obviously the problem here would be the proper credentials. But I have tried doing all sorts of impersonation stuff, whether from C# or in the script level. I tried doing this to the PowerShell script:
$username = "domain\user"
$password = ConvertTo-SecureString –String "password" –AsPlainText -Force
$pp = new-object -typename System.Management.Automation.PSCredential -argumentlist $username,$password
start-process powershell -argument "C:\localfolder\CopyFile.ps1" -Credential $pp
It works when I run the script in the PowerShell console locally, even when using an account that has no permissions to the network, however when called from the web app.. nothing happens.
The App Pool Identity is just set to the default App Pool Identity though.. I found out that if I change the identity to a custom account with the proper rights.. it works.
I am still trying to search for a different solution.. I want a scenario that you can just change anything in the script and it will still still run. Any is OK as long as it does not change the app pool identity.
I tried these as well:
http://huddledmasses.org/using-alternate-credentials-with-the-filesystem-in-powershell/
using runspace in c# instead of process and using an impersonator How do you impersonate an Active Directory user in Powershell?
But it still doesn't work. I keep on getting access denied. Question is, is it possible to make it work by impersonating someone inside PowerShell?
App pool identities have very limited access to the local file system (and none outside the local computer). You will need to modify ACLs on the file system to give the identities the access they need.
In Server 2008 (or Vista) this has to be done with the command line (eg. icacls.exe) as the permissions GUI does not support app pool identity; with later versions this can be done with the GUI.
Process Monitor is a good tool for working out where access is being blocked.
However if you need to access network resources this will not work. App pool identities are purely local, they have no meaning on the network. You need to use a domain account with the applicable access (or multiple local accounts with the same name and password).

Resources