Problem with SSAS connection with my ASP.NET web service - c#

I'm creating a web service that reads a file that contains a XMLA query and execute it against SSAS. My problem is that everything works locally, but when I publish my solution on a Windows Server 2008 R2 an exception keeps being generated.
Here is my code:
private String sendXMLARequest(String sXMLARequest, String sTargetServer, StreamWriter logger)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(sXMLARequest);
String Json = JsonConvert.SerializeXmlNode(doc);
Server server = new Server();
server.Connect(sTargetServer);
server.Execute(sXMLARequest);
XmlaResultCollection rsCollection = server.Execute(sXMLARequest);
string dis = server.Version.ToString();
String s = null;
foreach (XmlaResult res in rsCollection)
{
s += res.Value.ToString();
foreach (XmlaMessage message in res.Messages)
{
logger.WriteLine(message.ToString());
if (message is XmlaError)
Json = s + "ERROR : " + message.Description;
else
Json = s + "WARNIN : " + message.Description;
}
}
server.Disconnect();
JavaScriptSerializer js = new JavaScriptSerializer();
return js.Serialize(Json.ToString()); ;
}
EXCEPTION : Microsoft.AnalysisServices.ConnectionException: A
connection cannot be made. Ensure that the server is running. --->
System.IO.IOException: Unable to read data from the transport
connection: An existing connection was forcibly closed by the remote
host. ---> System.Net.Sockets.SocketException: An existing connection
was forcibly closed by the remote host

Related

Get SQL Server public x509 Certificate

How can I get/inspect the certificate used on SQL Server to encrypt the connection?
I need to retrieve and inspect the certificate, and if possible do some custom validation
This code works for most things, except SQL Server it just times out
var sqlServer = "sqlserver-fqdn";
using (var client = new TcpClient())
{
client.SendTimeout = 10000;
client.ReceiveTimeout = 10000;
await client.ConnectAsync(sqlServer, 1433).ConfigureAwait(false);
using (var stream = client.GetStream())
using (var sslStream = new SslStream(stream, false,
(sender, certificate, chain, policyErrors) =>
{ /* do some validation */ }, null))
{
sslStream.AuthenticateAsClient(sqlServer);
}
}
Throws exception:
System.IO.IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond..
---> System.Net.Sockets.SocketException (10060): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Setting ServicePointManager.ServerCertificateValidationCallback += CertificateCallBack; has no effect, it's only used for http clients

Unable to create a sink via the cloud logging api when on the production server

in development, I have working .net core c# code that checks for a sink and creates it if not present:
var builder = new ConfigServiceV2ClientBuilder { JsonCredentials = key, QuotaProject = billingProjectId };
var sinkClient = await builder.BuildAsync(cancellationToken);
LogSink? sink;
try
{
sink = await sinkClient.GetSinkAsync(new LogSinkName(clientProjectId, sinkName), cancellationToken);
}
catch (Exception ex)
{
if (ex.Message.Contains("NotFound"))
{
sink = new LogSink
{
Name = "sink-test",
Disabled = true,
Description = "A sink",
Destination = $"bigquery.googleapis.com/projects/{clientProjectId}/datasets/bq_logs",
Filter = #"
protoPayload.methodName=""jobservice.jobcompleted""
resource.type=""bigquery_resource""
protoPayload.serviceData.jobCompletedEvent.job.jobStatistics.totalBilledBytes!=""0""
"
};
sink = await sinkClient.CreateSinkAsync(ProjectName.FromProject(clientProjectId), sink); // fails on production server
}
}
However, when I run it in production, the get works, but the create fails:
GetSinkAsync Status(StatusCode="NotFound", Detail="Sink sink-test does not exist")
CreateSink Failure after 10028.3424ms: Status(StatusCode="Unavailable", Detail="Error starting gRPC call. HttpRequestException: The connection timed out from inactivity. (logging.googleapis.com:443) QuicException: The connection timed out from inactivity.", DebugException="System.Net.Http.HttpRequestException: The connection timed out from inactivity. (logging.googleapis.com:443)
We've tested for several days over several projects with no joy.

ASP.NET Web API : An existing connection was forcibly closed by the remote host

Web Api
[HttpGet]
[RequireHttps]
[Route("Api/GetString")]
public string GetString()
{
return "Worked";
}
RequireHttpsAttribute class
public class RequireHttpsAttribute : AuthorizationFilterAttribute
{
public override void OnAuthorization(HttpActionContext actionContext)
{
if (actionContext.Request.RequestUri.Scheme != Uri.UriSchemeHttps)
{
actionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.Forbidden)
{
ReasonPhrase = "HTTPS Required"
};
}
else
{
var cert = actionContext.Request.GetClientCertificate();
if (cert == null)
{
actionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.Forbidden)
{
ReasonPhrase = "Client Certificate Required"
};
}
base.OnAuthorization(actionContext);
}
}
}
Client (console)
HttpWebRequest client = (HttpWebRequest)WebRequest.Create("https://localhost:44315/api/GetString");
var cert = new X509Certificate2(File.ReadAllBytes(#"C:\ConsoleClient\TestCertificate.pfx"), "password");
client.ClientCertificates.Add(cert);
HttpWebResponse resp = (HttpWebResponse)client.GetResponse();
using (var readStream = new StreamReader(resp.GetResponseStream()))
{
Console.WriteLine(readStream.ReadToEnd());
}
This https request throws error.
Inner Exception Message : Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
Message : The underlying connection was closed: An unexpected error occurred on a send.
I opened port 443 and tried some settings mentioned in answers of same type of questions but couldn't resolve. Direct access to https://localhost:44315/api/GetString via browser is also not working.
If I change the https to http, it works fine.
Is anything needs to be configured?
Thanks.
The solution for me was updating the https protocol from the default ssl3 to tls via https://stackoverflow.com/a/46223433/352432

MongoDB Could not connect to remote server

I am not able to connect remote mongodb from my asp.net application. Though I am able connect it through mongo console.It gives me following error
"An exception of type 'MongoDB.Driver.MongoConnectionException'
occurred in MongoDB.Driver.dll but was not handled in user code
Additional information: Unable to connect to server troup.mongohq.com:10035: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."
Also I am able to connect my asp.net application from my local database.
Here is my code to connect mongodb by c#
var connectionString = "mongodb://appuser:xxxxx;#troup.mongohq.com:10035/PowrOfYouDev2";
var client = new MongoClient(connectionString);
var server = client.GetServer();
var database = server.GetDatabase("PowrOfYouDev2");
var collection = database.GetCollection<Entity>("Test");
var entity = new Entity { Name = "Tom" };
collection.Insert(entity);
var id = entity.Id;
var query = Query<Entity>.EQ(x => x.Id, id);
entity = collection.FindOne(query);
string str = entity.Name;
I am inserting image of error
Please help me.
Way late... But is there a reason you had that semicolon in the path?
"mongodb://appuser:xxxxx;#troup.mongohq.com:10035/PowrOfYouDev2
Seems like it should have been:
"mongodb://appuser:xxxxx#troup.mongohq.com:10035/PowrOfYouDev2

ClientContext.ExecuteQuery() produces connection error message

I am trying to run ClientContext.ExecuteQuery() and I am getting the following error message:
"The underlying connection was closed: A connection that was expected to be kept alive was closed by the server." >> "Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."
My code is as follows:
ClientContext _clientcontext = new ClientContext("<URL of sharepoint site>");
NetworkCredential _cred = new NetworkCredential("userid", "password", "domain");
_clientcontext.Credentials = _cred;
Web _site = _clientcontext.Web;
CamlQuery _query = new CamlQuery();
try
{
_query.ViewXml = <View><Where><Eq><FieldRef Name=\"Created\"/><Value Type=\"DateTime\"><Today OffsetDays=\"-4\"/></Value></Eq></Where></View>";
List _splist = _site.Lists.GetById(new Guid("<GUID>"));
ListItemCollection _listitems = _splist.GetItems(_query);
_clientcontext.Load(_listitems);
_clientcontext.ExecuteQuery();

Categories

Resources