I have been experiencing run-time errors in my application since the project files were moved to a new file server this past weekend as well the retirement of several old domain controllers. One is an LdapException (The connection cannot be established) when creating a new PrincipalContext as in the code below:
WindowsPrincipal wp = new WindowsPrincipal(WindowsIdentity.GetCurrent());
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain))
{
UP = UserPrincipal.FindByIdentity(pc, wp.Identity.Name);
}
I've tried a number of things including specifying various domain names and my network administrator has tried several things, but no luck.
I am also receiving an EntityException (The underlying provider failed on Open) when trying to get data from my MySQL database using EF as in the following code (crashes on the second line).
p = new pEntities();
Statuses = new ObservableCollection<status>(p.statuses);
I've taken several drastic steps that haven't solved my issues:
Uninstalled and reinstalled Visual Studio
Uninstalled and reinstalled MySQL
Deleted my user profile (this fixed some errors I was getting in VS, but not he run-time errors in the application itself)
I've tested the code in a completely new project and get the same errors, so it doesn't seem related to the project itself. I've also read quite a few SO and other posts on the two errors, but haven't been able to figure anything out. Is there something else I should be doing?
UPDATE
So, I moved my project to a local drive (C:) rather than the network, and now both errors are resolved, but I have no idea why that would fix it. Are there any known issues with running projects from networks drives that could cause these types of errors?
Related
I'm writing a WPF application.
Trying to use the normal method of getting a connection returns an error similar to: "The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine."
ACE.OLEDB has never been installed on this machine so this error makes sense.
I'm trying to create this application in a way so that our users won't need to contact IT to have the application installed. Getting IT involved is a no go situation and the project will be abandoned.
Another team has an Access database (accdb) that I want my application to extract information (only read, no insert or update). I talked to the team and they won't convert this database back to an earlier version (mdb).
After my research I assume that installing ACE.OLEDB without using Admin privileges is impossible. Because of this and my application requirement of not requiring admin privileges I need to start looking for "Mutant"/Dirty solutions that don't involve ACE.OLEDB.
I tried using power-shell but I'm getting the same problems as I had with C# (requires IT to install ACE.OLEDB).
I have two potential solutions. One write a VBA script that opens up the database and dumps a query result into a file. My C# application would call this VB script and then parse the created file.
The second option is to create a new Access process using Process.Start(fullFilePath) and somehow pass the command to execute a query and somehow pass the results back to the executing application (either via a method return or first to a file).
How would you get the data out?
Is there a way for C# to duplicate the DB file and convert it from (accdb -> mdb)?
This is the second question I ask that is very similar.
C# Connecting to Access DB with no install
The difference between the two (to prevent this is a duplicate question) is that in the previous question I was looking for ways to install ACE.OLEDB without admin privileges while here I'm just looking for any other work around.
Found a workaround. It uses Microsoft.Office.Interop.Access found in NuGet.
var accApp = new Microsoft.Office.Interop.Access.Application();
accApp.OpenCurrentDatabase(#tests.DatabasePath);
Microsoft.Office.Interop.Access.Dao.Database cdb = accApp.CurrentDb();
Microsoft.Office.Interop.Access.Dao.Recordset rst =
cdb.OpenRecordset(
"SELECT * FROM Users",
Microsoft.Office.Interop.Access.Dao.RecordsetTypeEnum.dbOpenSnapshot);
while (!rst.EOF)
{
Console.WriteLine(rst.Fields["username"].Value);
rst.MoveNext();
}
rst.Close();
accApp.CloseCurrentDatabase();
accApp.Quit();
This morning I started noticing some problems with several of my programs regarding Active Directory read operations. I noticed that all those applications (client and server) use the System.DirectoryServices.AccountManagement.UserPrincipal class for those read operations, while the programs still running correctly use System.DirectoryServices.DirectorySearcher.
So in order to narrow the problem down, I built the following, very simple console application
class Program
{
static void Main(string[] args)
{
//this works great
Console.WriteLine($"Enviroment.Username:{Environment.UserName}");
//this works great
PrincipalContext pcFull = new PrincipalContext(ContextType.Domain, "my.company.de", "dc=my,dc=company,dc=de");
UserPrincipal upPrincipalContextFull = UserPrincipal.FindByIdentity(pcFull, Environment.UserName);
//this doesn't work at all
//Exception: “The specified directory service attribute or value does not exist”
PrincipalContext pc = new PrincipalContext(ContextType.Domain);
UserPrincipal upPrincipalContext = UserPrincipal.FindByIdentity(pc, Environment.UserName);
//this doesn't either, same exception
UserPrincipal upCurrent = UserPrincipal.Current;
Console.ReadKey();
}
}
As you can see in the comments, the two latter operations will fail on every Computer in the domain i tested it on, even though they worked perfectly for several years. The following Exception occurs when I call UserPrincipal.Currentor UserPrincipal.FindByIdentity(pc, Environment.UserName); without specifying the Container in the PrincipalContext:
System.Runtime.InteropServices.COMException: “The specified directory service attribute or value does not exist”
Here is what I know:
none of the applications that suddenly stopped working received an update within the last two weeks
all of those applications, the UserPrincipal.Current-Property and the UserPrincipal.FindByIdentity-Method worked perfectly yesterday
Workstations did not receive Windows or .Net updates in the last week
the phenomenon does not relate to a single workstation, user or OS, but occures for a lot of different users, on a lot of different machines running Windows 7 or 10.
Domain Controllers received updates a week ago. Apparently one of those updates has a known issue about LDAP queries: Due to a defect in WLDAP32.DLL, applications that perform LDAP referral chasing can consume too many dynamic TCP ports. It seems unlikely that this is the reason for the sudden failures because a) that patch was installed a week ago and the Problems only occurred today and b) the suggested Workarounds from Microsoft (restarting Services) don't have any effect
What might cause such a behavior "overnight"? If it really is related to a Windows update, other users will soon be experiencing this bug too!
I can obviously build Workarounds, so I don't have to use the failing methods and properties, but I still have to know why it stopped working in the first place.
Edit
To start with, it would be useful to understand the difference between
public PrincipalContext(ContextType contextType); and public PrincipalContext(ContextType contextType, string name, string container);. The PrincipalContext constructed without container still has to obtain that container somehow, doesn't it?
By default the PrincipalContext searches in the "OU=Computers"-Container.
This fails if the reading permission is not set for the Container and will throw a COM Exception.
i am trying to create an app, which automatically creates and configures merge replication between the 2 PCs in the same local network.
To achieve this, i need to programaticaly create one user on each of the two PCs, this user should have exactly the same user name and passwords as it is required by the replication.
There is no DOMAIN on the network.
I did everything using GUI on both machines and replication works, now i need to do this using a C#. The replication part is done using SQL server 2012 RMO and SMO SDKs.
While googling, i found this (and many many other results which are more or less identical to this). But i believe, that these all examples are meant for local PCs, as it seems people were not getting errors like i do.
My sample code is:
DirectoryEntry directoryEntry = new DirectoryEntry(#"WinNT://WORKGROUP/WIN7-PC,computer", #"admin", "123456");
DirectoryEntry user = directoryEntry.Children.Add("RepTest", "user");
user.Invoke("SetPassword", new object[] { "rep123" });
user.CommitChanges();
I get an error at user.CommitChanges() saying that Access is denied, so i figured i had made a mistake in the authentication details provided to new DirectoryEntry(.... I fixed that and tried again:
DirectoryEntry directoryEntry = new DirectoryEntry(#"WinNT://WORKGROUP/WIN7-PC,computer", #"win7-pc\admin", "123456");
DirectoryEntry user = directoryEntry.Children.Add("RepTest", "user");
user.Invoke("SetPassword", new object[] { "rep123" });
user.CommitChanges();
Now I get the error on the line of .Children.Add(... stating that Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed.
When the first time i did it, i checked the Path of user object, which was WinNT://WORKGROUP/WIN7-PC/RepTest, not sure if it has anything to do with anything, but maybe it is trying to use the yet to be created new user folder while being connected as admin user?
Is there a way to get this thing going?
I am trying to solve a boring issue with an EF 6 data context now for several hours, though the entire code is small and simple. I did the same within the same solution already a couple of times and I never encountered this problem. Even when I compare the different implementations, configurations and references, I cannot find a difference. Here is the (very small) code snippet:
using (var context = new ConnectorDataContext())
{
var customer = context.Customers.FirstOrDefault();
}
Of course, there is more inside the using after the query, but it is not relevant whether it is there or not.
The collection is defined as
DbSet<ConnectCustomer> Customer {get;set;}
The context is derived from DbContext. Everything is attributed correctly (was copied from other, well working code parts of the solution.
The connection string points to a database which is used in other parts of the solution too. Yet, the test is isolated, so there is definately no other open connection.
But now, with this one, I always get an EntityException, caused by the underlying Provider, with an inner exception of "Overflow caused by the arithmetic operation". I am really close to desperation. Please help.
I've been battling a similar issue for far too long, and have only seen it emerge since upgrading to EF 6.x (not that I can conclusively say this is the cause). In my case, all calls to entity framework extension methods result in the "Arithmetic Overflow on Open" exception. Additionally, I only see this issue with IIS (any version), not IIS Express.
I found the following combination of things fixed the issue for me:
Manually clean your deployment location (del your obj and bin folders), try creating a new DB and point to it instead
Ensure your App Pool in IIS has "Enable 32-Bit Applications" set to True (right click on App Pool -> Advanced Settings)
Ensure that your database accepts remote connections - SQL Server Mgmt Studio, Right click on DB Server Instance -> Properties -> Connections -> Check the "Allow remote connections to this server" box
Ensure that DTC allows "Remote Clients": Windows Search for "Component Services" -> expand Computers -> My Computer -> Distributed Transaction Coordinator -> Right Click on "Local DTC" -> properties -> Security Tab -> Check Network DTC Access, Allow Remote Clients, Allow Inbound and Allow Outbound Transaction Manager Communication
Ensure that your Connection String is legit. I find this useful: http://www.developerfusion.com/tools/sql-connection-string/
Best of luck
I had the same issue. The application worked fine and then it suddenly started with the exceptions (no apparent changes in the code were made).
The solution was uninstalling program called "Web Companion" (I accidentally installed it by installing something else and not unticking during the installation process).
Therefore if you suddenly get these errors for no apparent reason, check for recent programs installed on your machine. Some of them can apparently cause it.
I am running the following code:
ManagementClass oMClass = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection colMObj = oMClass.GetInstances();
which is throwing this exception:
System.Management.ManagementException: Not found
at System.Management.ThreadDispatch.Start()
at System.Management.ManagementScope.Initialize()
at System.Management.ManagementObject.Initialize(Boolean getObject)
at System.Management.ManagementClass.GetInstances(EnumerationOptions options)
at System.Management.ManagementClass.GetInstances()
I went to check on the running services on Windows XP and found that Windows Management Instrumentation service has a status of 'Started'. I tried restarting the service but that didn't do any good.
I then tried to get the status of this service from within my running code using the ServiceController class:
ServiceController wpiService = new ServiceController();
wpiService.ServiceName = "Winmgmt";
string wmiStatus = wpiService.Status.ToString();
MessageBox.Show("WMI status= " + wmiStatus);
wmiStatus evaluates to 'Running'.
I have seen this error on only one of multiple machines running the same software. What's peculiar is that the machine was running smoothly for months, and then suddenly started showing this error.
Any clue as to what might be causing this?
I have also run into this issue. Here is one of the previously mentioned online resources explaining how one can fix WMI:
http://windowsxp.mvps.org/repairwmi.htm
The method of repairing seems to be different between different versions of Windows as explained on that page.
I had this problem on none of these versions, but on Windows Embedded Standard 2009. Since Windows XP Service Pack 2 is closest related to the listed OSes, that is the one I used:
For Windows XP Service Pack 2
Click Start, Run and type the following command:
rundll32 wbemupgd, UpgradeRepository
This command is used to detect and repair a corrupted WMI Repository. The results are stored in the setup.log (%windir%\system32\wbem\logs\setup.log) file.
The solution was to repair WMI on Windows XP. I don't have the detailed step by step fix (I'm not the one who implemented the fix), but my understanding is that a repository related to this service can get corrupted and there's a Windows utility that can repair it. There are several online resources on how to do this.