Unable to connect RavenDB Cloud, in Microservice (AWS Lambda) - c#

Problem statement
Trying to connect RavenDB Cloud service using AWS Lambda function, for one of my POC, but failed to connect.
Background
I am using the client certificate (.pfx) file for this. It throws error exactly during certificate assign with X509Certificate2. I have converted the certificate to byte[] and passed. The certificate I am using has full access to the database. I am included the error below
Code
if (_bClientCertificate != null)
{
if (_bClientCertificate.Length > 0)
{
xclientCertificate = new X509Certificate2(_bClientCertificate);
}
}
IDocumentStore store = new DocumentStore()
{
Certificate = xclientCertificate, //Error occured here
Urls = _Urls,
Database = _DBName
}.Initialize();
Exception Details :
System.IO.FileLoadException
HResult=0x80131509
Message=Could not load file or assembly 'Sparrow, Version=4.2.2.0, Culture=neutral, PublicKeyToken=37f41c7f99471593'. An operation is not legal in the current state. (Exception from HRESULT: 0x80131509)
Source=Raven.Client
StackTrace:
at Raven.Client.Documents.Subscriptions.DocumentSubscriptions..ctor(IDocumentStore store) in C:\Builds\RavenDB-Stable-4.2\42017\src\Raven.Client\Documents\Subscriptions\DocumentSubscriptions.cs:line 33
at Raven.Client.Documents.DocumentStoreBase..ctor() in C:\Builds\RavenDB-Stable-4.2\42017\src\Raven.Client\Documents\DocumentStoreBase.cs:line 28
at Firecloud.DataAccess.RavenDB.SessionStore.CreateStore() in C:\Works\SourceCode\FC\Library\RavenDB\FC.DataAccess.Raven\SessionStore.cs:line 87
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)

I've had this issue before, apparently some visual C++ libraries could be missing.
Try installing Visual C++ Redistributable for Visual Studio 2015.

Related

Common Oracle Client Connection Issue with a Console .NET 4.7 program: Could not load file or assembly 'Oracle.DataAccess, Version=2.121.2.0

I download the Oracle client was downloaded from https://www.oracle.com/database/technologies/oracle19c-windows-downloads.html and select the file "NT_193000_client.zip" under the heading "Oracle Database 19c Client (19.3) for Microsoft Windows (32-bit)".
I then installed it on my server. When I run a TNSPing command to check the version number and bit-ness of the Oracle Client installed, I get:
TNS Ping Utility for 32-bit Windows: Version 19.0.0.0.0 - Production on 20-OCT-2022 22:50:49
I then used SQLPlus to verify that I could connect to the database.
Next, I compiled the following simple C# program that tests Oracle connectivity. The program was compiled as a 32-bit .NET 6 program.
using System;
namespace TestOracle
{
internal class Program
{
static void Main(string[] args)
{
string cs = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=servernm.sys.myco.com)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=MySERVICE.MYCO.com)));User Id=MYID;Password=MYPWD;Validate Connection=True;";
try
{
int count = Db.TestConnectivity(cs);
Console.WriteLine($"Count={count}");
}
catch (Exception e)
{
Console.WriteLine(e);
}
var key = Console.ReadKey();
}
}
}
using Oracle.DataAccess.Client;
using System;
using System.Data;
using System.Text;
namespace TestOracle
{
public static class Db
{
public static int TestConnectivity(string connectionString)
{
var sqlStringBuilder = new StringBuilder();
sqlStringBuilder.AppendLine($"SELECT 1 AS RecordCount FROM DUAL");
using (OracleConnection connection = new OracleConnection(connectionString))
{
connection.Open();
OracleCommand command = connection.CreateCommand();
command.Connection = connection;
var oleDbDataAdapter = new OracleDataAdapter(command);
command.CommandText = sqlStringBuilder.ToString();
DataSet dataset = new DataSet();
oleDbDataAdapter.Fill(dataset);
return Convert.ToInt32(dataset.Tables[0].Rows[0]["RecordCount"]);
}
}
}
}
When I ran the program, I get this error:
System.IO.FileNotFoundException: Could not load file or assembly 'Oracle.DataAccess, Version=2.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. The system cannot find the file specified.
File name: 'Oracle.DataAccess, Version=2.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342'
at TestOracle.Db.TestConnectivity(String connectionString)
at TestOracle.Program.Main(String[] args) in C:\Users\C39293\OneDrive - CIGNA\Documents\Visual Studio 2015\Projects\Dokmanovich.File2Table\TestOracle\Program.cs:line 13
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
I know that this is a common error and that the common issue is a mismatch of bitness or a version problem. In my case, the bitness of my program, 32, matches the bitness of the client installed. Furthermore, I expect that if the program runs on my machine with an Oracle client of 12.1, that a higher level client, 19, should also work. Is this assumption true? I was unable to find the exact same oracle Client.
What am I missing?
Update
When I looked in my C# project References, I saw that the Oracle.DataAccess.dll pointed to my 64 Oracle client folder on my machine, not my 32 bit one ( I have both clients). Since I want to run on a server that only has the 32 bit Oracle client, I changed the reference to point to the 32 bit dll and re-compiled it as before, as a 32 bit program.
When I reran the program on the server, I got a different error:
System.TypeInitializationException: The type initializer for 'Oracle.DataAccess.Client.OracleConnection' threw an exception. ---> Oracle.DataAccess.Client.OracleException: The provider is not compatible with the version of Oracle client
at Oracle.DataAccess.Client.OracleInit.Initialize()
at Oracle.DataAccess.Client.OracleConnection..cctor()
--- End of inner exception stack trace ---
at Oracle.DataAccess.Client.OracleConnection..ctor(String connectionString)
at TestOracle.Db.TestConnectivity(String connectionString) in C:\Users\Myid\OneDrive - CIGNA\Documents\Visual Studio 2015\Projects\MyName.File2Table\TestOracle\Db.cs:line 15
at TestOracle.Program.Main(String[] args) in C:\Users\MyId\OneDrive - CIGNA\Documents\Visual Studio 2015\Projects\MyName.File2Table\TestOracle\Program.cs:line 13
I guess this is suggesting that I have the wrong Client. What should I have installed so this code runs on the server?
Update 2
I had two version of the 32 Oracle.DataAccess.dll, version 2.121.20 and 4.121.2.0. The error was the same for both (the error message immediately above).
You may consider to use the Oracle Data Provider for .NET, Managed Driver (ODP.NET Managed Driver), then you have to copy only the Oracle.ManagedDataAccess.dll file without any further dependencies. It works for both, 32bit and 64bit.
Apart from 32/64 bit you need to consider a few more things.
If you like to use Oracle.DataAccess Version=2.xxx, then you must compile to .NET Framework 2.0. If you compile to .NET Framework 4.0 or higher, then the application will try to load Oracle.DataAccess Version=4.xxx (unless you load assemblies manually with Assembly.Load())
The version of Oracle.DataAccess has to match exactly the version of the Oracle client. Using version 2.121.x or 4.121.x with a Oracle 19 client does not work.
Assemblies (i.e. *.dll files) are loaded either from GAC or from folder of the application .exe. Well, in reality it is more complex (see How the Runtime Locates Assemblies), but let's keep it simple.
The DLL files from GAC take always precedence over the local files. However, in 12.1 and later ODP.NET is not added to GAC anymore by the installer. You need to add them manually, for example with the gacutil tool.
Looks like on your machine you had a 64-bit Oracle client installed. If you like to use 32-bit and 64-bit client on the same machine, follow this instruction: BadImageFormatException. This will occur when running in 64 bit mode with the 32 bit Oracle client components installed
You may also have a look at my Oracle Connection Tester, it should give you a hint where the problem is.

Interop-Outlook error on Teamcity

I have several project which requires me to connect an email account and retrieve data from email arrives.
When running locally on my PC, everything works fine.
I have Teamcity (latest version) installed on a Windows 2008 server.
This is my code where it seems it fails:
public void DeleteAllEmails(string Folder)
{
Application myApp = new ApplicationClass();
NameSpace mapiNameSpace = myApp.GetNamespace("MAPI");
MAPIFolder myInbox = mapiNameSpace.GetDefaultFolder(OlDefaultFolders.olFolderInbox).Folders[Folder];
List<MailItem> ReceivedEmails = new List<MailItem>();
foreach (MailItem mail in myInbox.Items)
{ ReceivedEmails.Add(mail); }
foreach (MailItem mail in ReceivedEmails)
{
mail.Delete();
}
}
When running my tests from TeamCity, I get this error:
[ReportAppeal.dll] ReportAppeal.MainTestRunner.Create2ApplicationsTryOneWithcorrectReportIdSecondwithUncorrectReportId("PostOffice") (2m:06s)
[13:56:35][ReportAppeal.MainTestRunner.Create2ApplicationsTryOneWithcorrectReportIdSecondwithUncorrectReportId("PostOffice")] System.Runtime.InteropServices.COMException : Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
Or
[ReportAppeal.MainTestRunner.CheckStatusFor2ApplicationsOfTheSameCarNumber("PostOffice")] at ReportAppeal.Email.DeleteAllEmails(String Folder) in C:\BuildAgent\work\430330697c233f87\Projects\ReportAppeal\ReportAppeal\Email.cs:line 50
at ReportAppeal.MainTestRunner.CheckStatusFor2ApplicationsOfTheSameCarNumber(String Address) in C:\BuildAgent\work\430330697c233f87\Projects\ReportAppeal\ReportAppeal\MainTestRunner.cs:line 427
[13:50:09][ReportAppeal.dll] ReportAppeal.MainTestRunner.Create2ApplicationsButFinishProcessJustAfterOne("Email") (2m:07s)
I have Outlook 2013 installed on my server so the environments are pretty similar.
What could I do in order to make it work?

sqlserverspatial110.dll vs sqlspatial130.dll

I am trying to move a deployment to a new Azure VM with SQL Server 2016. I am receiving the following error when trying to run the mvc app locally on the server.
Unable to load DLL 'SqlServerSpatial110.dll': The specified module
could not be found. (Exception from HRESULT: 0x8007007E)
The fix for me was to manually copy sqlserver110.dll to the c:\windows\system32 folder on the new server. I feel this is a step backwards, and I should really be trying to redirect the call to the sqlserver130.dll that installed on the new server by default with SS 2016. I tried updating EF 5 to the latest version, but this did not seem to fix the issue. Any suggestions?

Get "Microsoft.SqlServer.Wmi.ServiceState" in .NET 4.0 Application

I'm connection to an Microsoft SQL Server 2008 in C# .NET 4.0 Application.
Now I want to display all sql Services from the remote computer.
ManagedComputer managedComputer = new ManagedComputer("ServerName", "Login", "Password");
foreach (var service in managedComputer.Services)
{
Console.WriteLine(service.Name + " | " + service.ServiceState);
}
The problem is, that I can't build the solution because Visual Studio 2012 brings the error, I should add an Assembly. Here is the error message:
The type 'Microsoft.SqlServer.Management.Smo.Wmi.ServiceState' is defined in an assembly that is not referenced. You must add a
reference to assembly 'Microsoft.SqlServer.WmiEnum, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=89845dcd8080cc91'.
Of course I added this assembly but still there is no change.
The problem comes from the Code service.ServiceState.
How can I fix this problem? Is this Assembly only for .NET 2.0?
Or is there any other way to get the status (running, stopped...) of an remote sql service?

SSCE 4 Unable to load native components exception from outlook plugin

We have a wpf .net app using SSCE 4 with private deployment and works great
however there's also a outlook plugin which throws up the following exception
System.Data.SqlServerCe.SqlCeException was caught
HResult=-2147467259 Message=Unable to load the native components of
SQL Server Compact corresponding to the ADO.NET provider of version
8876. Install the correct version of SQL Server Compact. Refer to KB article 974247 for more details. Source="" ErrorCode=-2147467259
NativeError=-1 StackTrace:
at System.Data.SqlServerCe.NativeMethods.LoadNativeBinaries()
at System.Data.SqlServerCe.SqlCeConnection..ctor()
at System.Data.SqlServerCe.SqlCeConnection..ctor(String connectionString)
at ZKB.initDB() in C:\ZKB\OutlookApi\dbInit.cs:line 42 InnerException:
when the following line is executed
SqlCeConnection connection = new SqlCeConnection(myConnStr());
Hooking into Assembly.Resolve shows it trying to locate
System.Data.SqlServerCe.resources, Version=4.0.0.1, Culture=en-US, PublicKeyToken=89845dcd8080cc91
and then the exception above comes up
SSCE 4 SP1 is installed on this machine
Any help on what could be wrong and how to resolve this ?
You cannot use private deployment from an Office addin, this will require you to place the sqlce dll files under the location of Outlook.exe (and not even sure that it will Work then)

Categories

Resources