I'm working with Entity Framework 5 and a MySQL DB and I'd like to save two new related entities at once:
var record = data.Records.Create();
record.Name = "Abbey Road";
data.Records.Add(record);
// Create the song
var song = data.Songs.Create();
song.Title = "Here Comes The Sun";
song.Record = record;
data.Songs.Add(song);
data.SaveChanges();
But it fails. The exception is:
System.Data.Entity.Infrastructure.DbUpdateException : Fehler beim Aktualisieren der Einträge. Weitere Informationen finden Sie in der internen Ausnahme.
----> System.Data.UpdateException : Fehler beim Aktualisieren der Einträge. Weitere Informationen finden Sie in der internen Ausnahme.
----> System.ArgumentException : Der angegebene Wert ist keine Instanz eines gültigen Konstantentyps.
Parametername: value
English Translation
System.Data.Entity.Infrastructure.DbUpdateException: Failed to update the entries. See the inner exception. ---> System.Data.UpdateException: failed to update the entries. See the inner exception. ---> System.ArgumentException: value specified is not a valid constant type an instance. Parameter name: value
Sorry, it's German. The first exception means the given value is not a valid type of constant. It looks like that the provider (mysql) wants to update something where it should use an insert.
Does anybody have an idea what it is?
Best regards,
Torsten
There are a lot of similar problems in combination with mySQL. Try change any unsigned columns in mysql to signed. EF doesn't support unsigned.
Hope this helps
Related
I am trying to query attached USB devices as follows (C#, .NET 4.5, Win10)
using (ManagementObjectSearcher mos = new ManagementObjectSearcher("select DeviceID, Model from Win32_DiskDrive where InterfaceType='USB'"))
{
ManagementObjectCollection coll = mos.Get();
foreach (ManagementObject drive in coll)
{
}
}
The interesting part is that I get an InvalidCastException on the Get() function, without any further info on the inner exception.
System.InvalidCastException ist aufgetreten. HResult=0x80004002
Nachricht = Die angegebene Umwandlung ist ungültig. Quelle = Stapelüberwachung:
Translation of above error message to English done in bing.com
System.InvalidCastException has occurred. HResult = 0x80004002
Message = the specified cast is not valid. Source = stack trace:
The more interesting part: If I step through, leaving a bit time between the construction of the ManagementObjectSearch and the collection of the Get() command, it works.
This sounds to me as if Get() runs asynchronously. Can anybody shed some light on this?
Update July, 2nd, 2017:
I checked on another system, and got another more informative error message (sorry for the german error message, maybe some of you can help me nevertheless :-):
Assistent für verwaltetes Debuggen "DisconnectedContext" ist
aufgetreten. HResult=0x00000000 Nachricht = Assistent für
verwaltetes Debuggen "DisconnectedContext" : "Folgender Fehler beim
Übergang in den COM-Kontext 0x16d4d48 für diesen
RuntimeCallableWrapper: Ein ausgehender Aufruf kann nicht ausgeführt
werden, da die Anwendung einen eingabe-synchronisierten Aufruf
weiterleitet. (Ausnahme von HRESULT: 0x8001010D
(RPC_E_CANTCALLOUT_ININPUTSYNCCALL)). Dieser tritt in der Regel auf,
da der COM-Kontext 0x16d4d48, in dem dieser RuntimeCallableWrapper
erstellt wurde, getrennt wurde oder aufgrund eines anderen Vorgangs
ausgelastet ist und den Kontextübergang deshalb nicht verarbeiten
kann. Es wird kein Proxy verwendet, um die Anfrage an die
COM-Komponente zu verarbeiten, und Aufrufe werden direkt an die
COM-Komponente gesendet. Dies kann Datenbeschädigung oder -verlust zur
Folge haben. Um dieses Problem zu vermeiden, müssen Sie sicherstellen,
dass alle COM-Kontexte/Apartments/Threads so lange beibehalten werden
und für den Kontextübergang verfügbar sind, bis die Anwendung alle
RuntimeCallableWrappers, die in ihnen enthaltene COM-Komponenten
darstellen, vollständig verarbeitet hat."
Error Translated to English in bing.com for quick response:
Managed debugging assistant "DisconnectedContext" has occurred. "
HResult = 0x00000000 message = "DisconnectedContext managed debugging
assistant ': "Folgender error during the transition to the COM context
of 0x16d4d48 for this RuntimeCallableWrapper: an outgoing call can not
run, because the application routes a call to input synchronized. "
(Exception from HRESULT: 0x8001010D
(RPC_E_CANTCALLOUT_ININPUTSYNCCALL)). This usually occurs because the
COM context therefore cannot process 0x16d4d48, in which this
RuntimeCallableWrapper was created, disconnected or is exhausted due
to other operation and the context transition. It uses no proxy to
process the request on the COM component, and calls are sent directly
to the COM component. May result in data corruption or loss result.
"To avoid this problem, you must ensure that all COM
contexts/apartments/threads so long be retained and available for the
context transition, until the application has completely processed all
RuntimeCallableWrappers that represent COM components contained in
them. "
Found the solution with the new error code RPC_E_CANTCALLOUT_ININPUTSYNCCALL when trying to access USB device
Don't really understand why this works though...
I have an asp.net MVC Webapplication who uses the excel interop to open a csv in an excel save the file as an xlsx and load the bytes from that file. These bytes are then passed as a download.
So far everything works as expected. but after the 6 download I get the following exception. Unfortunately it's on german, since the server is setup in german. But the exception message is something like "80080005 starting the server failed".
Die COM-Klassenfactory für die Komponente mit CLSID {00024500-0000-0000-C000-000000000046} konnte aufgrund des folgenden Fehlers nicht abgerufen werden: 80080005 Starten des Servers fehlgeschlagen (Ausnahme von HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
Beschreibung: Unbehandelte Ausnahme beim Ausführen der aktuellen Webanforderung. Überprüfen Sie die Stapelüberwachung, um weitere Informationen über diesen Fehler anzuzeigen und festzustellen, wo der Fehler im Code verursacht wurde.
Ausnahmedetails: System.Runtime.InteropServices.COMException: Die COM-Klassenfactory für die Komponente mit CLSID {00024500-0000-0000-C000-000000000046} konnte aufgrund des folgenden Fehlers nicht abgerufen werden: 80080005 Starten des Servers fehlgeschlagen (Ausnahme von HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
When I restart the website, it works again for the next 5-7 downloads.
here is my code for the excel:
private byte[] WriteExcel(SelectionResult result)
{
var csvPath = Path.Combine(Settings.Default.FileGenerationPath, DateTime.Now.ToString("yyMMMddhhmmss") + "_" +new Random().Next(1000, 9999)+".csv");
var excelPath = Path.Combine(Settings.Default.FileGenerationPath, DateTime.Now.ToString("yyMMMddhhmmss") + "_" + new Random().Next(1000, 9999)+".xlsx");
var excelApp = new Application();
File.WriteAllBytes(csvPath, WriteCsv(result, true));
var excelWorkbooks = excelApp.Workbooks;
excelWorkbooks.Open(csvPath, Delimiter: ",");
var workbook = excelApp.ActiveWorkbook;
workbook.SaveAs(excelPath, XlFileFormat.xlOpenXMLWorkbook);
excelWorkbooks.Close();
excelApp.Quit();
var bytes = File.ReadAllBytes(excelPath);
File.Delete(csvPath);
File.Delete(excelPath);
return bytes;
}
What do I miss?
According to Microsoft Support, that kind of error
You may receive an "Error code 80080005 -- server execution failed." error message when you start many COM+ applications
arise when you are using too many com applications. And you have a pretty much not disposed unmanaged resources. Every time use using statement in you are using input-output operations.
Update No. You don't. Closing an Excel is not releasing COM object while the application is running.
You need to:
//include marshal
using System.Runtime.InteropServices;
//release objects
Marshal.ReleaseComObject(excelApp);
Marshal.ReleaseComObject(excelWorkbooks);
Marshal.ReleaseComObject(workbook);
If there is an exception in .NET code and and PDB file is available you normally get the errors with source code line numbers shown in the exception message. This seems to be different in command line executables, where I do not get any line number although a PDB file is available:
Anwendung: MNX.CommandLine.EpkFtpEventhandler.exe Frameworkversion: v4.0.30319 Beschreibung: Der Prozess wurde aufgrund eines Ausnahmefehlers beendet. Ausnahmeinformationen: System.Data.SqlClient.SqlException Stapel: bei System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(System.String, Boolean, Int32, Boolean) bei System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(System.Threading.Tasks.TaskCompletionSource`1, System.String, Boolean, Int32, Boolean) bei System.Data.SqlClient.SqlCommand.ExecuteNonQuery() bei MNX.DB.WriteLocal(System.String) bei MNX.DB.Write(System.String) bei MNX.CommandLine.EpkFtpEventHandler.Main(System.String[])
Does anyone know why?
Use Stack Frames and surround you code with a try catch:
try
{
throw new Exception();
}
catch (Exception ex)
{
// Get stack trace for the exception with source file information
var st = new StackTrace(ex, true);
// Get the top stack frame
var frame = st.GetFrame(0);
// Get the line number from the stack frame
var line = frame.GetFileLineNumber();
// Print the line number
Console.WriteLine($"An Error ({ex.Message}) occurred in line {line}");
}
To avoid plagiarism: I got the idea from this question.
I don't know why it isn't normally displayed in your console application though, but this should do it as well.
Try to empty symbol cache by accessing Debug > Options > Debugging > Symbols and clean your solution afterwards.
Exception.StackTrace gave back the line number, when it comes from a catch. Strangely only when I catch the exception, not when it's thrown without being catched.
my Problem is as follows.
I generate a default Email(type of MailMessage) in C# and want to Send it through a smptclient. But before that I want to Open and Edit it in Outlook or whatever Email Program is installed. Right now I'm doing this:
message.Save(fileName, true);
Process.Start(fileName);
Save is an extension Method copied from this Post
But now ofcourse the Mailprogramm tries to Send the Mail itself... I Need however an default Sender. So if I try to Send it through Outlook I get an Error Mail like :
Ihre Nachricht hat einige oder alle Empfänger nicht erreicht.
Betreff: Test report 18.03.2016
Gesendet am: 18.03.2016 10:36
Folgende(r) Empfänger kann/können nicht erreicht werden:
Max Muster am 18.03.2016 10:36
Diese Nachricht konnte nicht gesendet werden. Versuchen Sie es später erneut, oder wenden Sie sich an den
Netzwerkadministrator. Sie besitzen nicht die Berechtigung, die
Nachricht im Auftrag des angegebenen Benutzers zu senden. Fehler:
[0x80070005-0x0004dc-0x000524].
Which translated boils down to :
Couldn't deliver Mail. You don't have Permission to Send the Message from the specified User. Error: [0x80070005-0x0004dc-0x000524]
Sorry I don't have an English Error Message.
Is there any way to pass an specific SMPT Server to a mailObject? So that any Email program opening the Mail, will use this Server instead?
I have the following problem:
I am using a German Windows7-machine (Culture: "de-DE"), but I want to use the SpeechRecognitionEngine-class with an other culture.
However, the following code throws an ArgumentException:
using (SpeechRecognitionEngine rec = new SpeechRecognitionEngine(new CultureInfo("en-GB"))) //ArgumentException
{
rec.LoadGrammar(new DictationGrammar("grammar:dictation#spelling"));
rec.SpeechRecognized += rec_SpeechRecognized;
rec.SetInputToDefaultAudioDevice();
rec.RecognizeAsync(RecognizeMode.Multiple);
...
}
The Exception message is the following:
Es wurde kein Erkennungsmodul mit der erforderlichen ID gefunden.
Translation:
No recognition module with the required ID could be found.
Does this mean, that some sort of language package is missing on my machine?
I suggest the en-GB-packet has to be installed on the machine.
EDIT:
It would be also reasonable to use a try catch block to prevent the app from crashing if the packet is not available.