Is it possible that SqlException will be thrown when trying to execute sql procedure and property Number will be 0?
Specific situation: domain controller is not available/not responding and no real communication with sql server occurred.
No, it should not be possible that SqlException.Number is 0, except for the following cases:
Read-only routing failure
Server had severe error processing query
Processed cancellation while parsing results
Failed to create user instance
Assuming you're not using read-only routing of SQL Server 2016, then none of these cases could apply to the scenario you described.
Remaining cases are either a non-zero number from sysmessages, or a Win32 error code (which, since 0 == ERROR_SUCCESS, would also never be zero).
In practice you will see something along the lines of "Cannot create SSPI context", or "A transport-level error has occurred when sending the request to the server", or a "An existing connection was forcibly closed by the remote host", and those have nonzero Win32 error codes too.
Reference: https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlerror.number(v=vs.110).aspx
It may be worth noting that SqlException.Number is synonym for the Number property of the first entry in its Errors array, and that array might contain more than one item.
Answering my own question. Yes, it is possible. We added aditional code to catch:
catch (SqlException ex)
{
for (int i = 0; i < ex.Errors.Count; i++)
{
this.logger.Error("Index #" + i + "\n" +
"Message: " + ex.Errors[i].Message + "\n" +
"Error Number: " + ex.Errors[i].Number + "\n" +
"LineNumber: " + ex.Errors[i].LineNumber + "\n" +
"Source: " + ex.Errors[i].Source + "\n" +
"Procedure: " + ex.Errors[i].Procedure + "\n");
}
if (ex.Number == 0)
{
this.logger.Warn("Exception was caught but ex.Number == 0! Changing to -69.");
oResults.Add("_ExitCode", "-69");
}
}
and this was logged today.
2017-01-17 08:05:08,282 [r074008903] ERROR ProcessLogger Index #0
Message: A severe error occurred on the current command. The results, if any, should be discarded.
Error Number: 0
LineNumber: 0
Source: .Net SqlClient Data Provider
Procedure:
2017-01-17 08:05:08,282 [r074008903] ERROR ProcessLogger Index #1
Message: A severe error occurred on the current command. The results, if any, should be discarded.
Error Number: 0
LineNumber: 0
Source: .Net SqlClient Data Provider
Procedure:
2017-01-17 08:05:08,283 [r074008903] WARN ProcessLogger Exception was caught but ex.Number == 0! Changing to -69.
Because in other place _ExitCode was used to determine is something was wrong in this specific situation we had false information.
It is possible.
I receive 0 when trying to connect SQL which is starting inside ubuntu container. According to this: https://learn.microsoft.com/en-us/sql/relational-databases/errors-events/database-engine-events-and-errors?view=sql-server-ver15
that is undocumented and, probably, is a bug.
Here is my situation, for example:
Related
I have a TM-T20 Epson, I'm using this code to try to print : "Hello Printer" Message, and i keep tracking of some proprieties of the PosPrinter :
public void ImprintHelloPrinter()
{
//The Explorer
PosExplorer explorer = new PosExplorer();
////Get the device by its type LOGICAL NAME
DeviceInfo device = explorer.GetDevice(DeviceType.PosPrinter, "T20PRINTER");
//Create an instance
PosPrinter oposPrinter = (PosPrinter)explorer.CreateInstance(device);
//Opening
MessageBox.Show(#"Statue : " + oposPrinter.State.ToString());
oposPrinter.Open();
MessageBox.Show(#"Statue : " + oposPrinter.State.ToString());
//Checking if its really the printer
MessageBox.Show(#"Description : " + oposPrinter.DeviceDescription);
MessageBox.Show(#"Check Claimed : " + oposPrinter.Claimed.ToString());
oposPrinter.Claim(10000); //Here is My Exception
//Enabeling device
oposPrinter.DeviceEnabled = true;
//normal print
oposPrinter.PrintNormal(PrinterStation.Receipt, "Hello Printer");
}
Everything went OK, i checked that it is the right Printer and it opened and its not claimed, but when i try to Claim it i have the following Exception :
Method ClaimDevice threw an exception. Attempt was made to perform an illegal
or unsupported operation with the device, or an invalid parameter value was used.
Even in the Example application provided with the Microsoft Point Of Service SDK in the Sample Application Folder (C:\Program Files\Microsoft Point Of Service\SDK\Samples\Sample Application), i can find my printer, open it, but when i Claim it i have this error message :
POSControlException ErrorCode(Illegal) ExtendedErrorCode(10002) occurred:
Method ClaimDevice threw an exception. Attempt was made to perform an illegal
or unsupported operation with the device, or an invalid parameter value was
used.
Print Screen Of The Sample Application :
The error is because you have bad port configurated.
In my case, I use model FP-81 II connected to hardware NPort 5110 where I was configure port to 9100.
I hope help you.
Trying to complete a web process, however, I am receiving a 'request time out' error. I'm not sure what I can do to get around this.
I modified the method to create a new connection for every number being passed in the for loop, but it seems to be yielding the same result.
I am more of a desktop developer, not overly versed in ASP.Net, so any light that could be shed on my issue would be great.
I've looked up info on ASP background workers, which doesn't seem to be a great way to go, and I've increased the server settings to allow a higher timeout, but still timeout if a huge number of parts are provided.
I'm also trying to avoid a separate process that is scheduled on the server to execute a submitted list of numbers. If more info is needed to make sense of this, just let me know.
Also, when I attempt to run the application locally (debug) there are never issues, only when it's placed on the live site.
Here is the exact error received:
Server Error in '/' Application.
Request timed out.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Request timed out.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[HttpException (0x80004005): Request timed out.]
And here is the code:
protected void btnSearch_Click(object sender, EventArgs e)
{
// Clear our reporting panel.
panelHolder.Controls.Clear();
// Store each line in a new array item.
string[] searchlines = txtboxSearch.Text.Replace("\n", "|").Split('|');
// Create a table row containing our main table headers.
panelHolder.Controls.Add(new LiteralControl("<table style=\"width:100%;\">" +
" <tr> " +
" <td></td> " +
" <td>Number</td> " +
" <td>Comparison</td> " +
" </tr>"));
// Variable to hold the row counts.
int j = 0;
// Store our current web members name for use in our tracking data.
string MemberName = Member.GetCurrentMember().Text;
// This table will be used solely for storing our excel exported data.
System.Data.DataTable dt = new System.Data.DataTable();
// Locate our part comparison results for every line of data supplied by our users.
for (int i = 0; i < searchlines.Count(); i++)
{
using (SqlConnection con = new SqlConnection(dbConnection))
{
// If this array item is not blank we will need to collect information about it.
if (searchlines[i].Trim() != string.Empty)
{
// Determine if data collection (reporting) is turned on.
Boolean isReporting = DataCollection();
using (SqlDataReader dr = Connect.ExecuteReader("SelectNumbers]", con,
new SqlParameter("#Number", searchlines[i].Trim()),
new SqlParameter("#CurrentMember", MemberName),
new SqlParameter("#DataCollection", isReporting)))
{
if (dr.HasRows)
{
while (dr.Read())
{
// Add our table rows containing our returned data set.
panelCompetitorHolder.Controls.Add(new LiteralControl("<tr><td>" + Convert.ToString(i + 1) + "</td>"));
AddTableData(dr, "Part Number");
AddTableData(dr, "Comparison");
// Go to our next line item.
j += 1;
}
}
}
}
}
}
// Add our table to the panel control.
panelHolder.Controls.Add(new LiteralControl("</table>"));
}
Your issue may lie in the fact that IIS assumes a maximum period of time for a given request to be processed. By default, the value is 90 seconds. Here's a few ways you can set a different amount of time:
Via Web.config - Check/add this entry on your web.config file:
<system.web>
<httpRuntime executionTimeout="N" />
</system.web>
Programatically - You may add this to your server-side code:
Server.ScriptTimeout = N;
Where N is, in both options, the desired amount of seconds for the request timeout.
Additionally, your values may be superseded/ignored if there's an entry present at the server's applicationhost.config or machine.config files, as described here:
http://www.iis.net/configreference/system.applicationhost/sites/sitedefaults/limits
If that's the case you may have to alter the corresponding entries - or, in lieu of that, alter your codebehind content.
I am writing a code to copy files from one directory to another. I am picking the file path from a 2D array.
for (int row = 1; row <= numRows; ++row)
{
path = valueArray[row, 13].ToString();
fileName = valueArray[row, 4].ToString();
CopyDirectory.myCopy(path, "C:\\TestCopyDest", fileName);
}
The above program copies the first directory well. However, it then generates an exception:
A first chance exception of type 'System.IO.IOException' occurred in mscorlib.dll.
What should I do? Do I need to create different threads for copying?
A First Chance Exception doesn't mean your code has a problem.
Read the above link.
I think this will help you
First chance means the program hasn't been able to deal with it yet, the debugger comes first. When you let it through, the app will deal with it nicely, so you don't get errors.
You should set up Visual Studio to ignore thrown (1st chance) exceptions, and only break on unhandled ones.
Comment out the action line and write out the contents of your strings to make sure you're getting valid paths and don't have dupe file names:
Console.WriteLine("path: " + path + ", file: " + fileName);
//CopyDirectory.myCopy(path, "C:\\TestCopyDest", fileName);
Did you mean to copy everything into 1 target folder?
Your program is running as a 64-bit process. Your DLL contains 32-bit unmanaged code.
I'm trying to delete all the emails from a mailbox using the Koolwired.Imap library. I have the following code that should be marking all the messages and they, once all are marked, delete them,
_mailbox = _command.Fetch(_mailbox);
foreach (ImapMailboxMessage m in _mailbox.Messages)
{
try
{
_command.SetDeleted(m.ID, true);
}
catch (Exception e)
{
Console.WriteLine("Marking Error: " + e.Message + "(" + m.MessageID + ")");
}
}
try
{
_command.Expunge();
}
catch (Exception e)
{
Console.WriteLine("Expunge Error: " + e.Message);
}
When I run the above code i get the following errors:
Marking Error: Input string was not in a correct format.()
Marking Error: No UID found for message number3()
Marking Error: No UID found for message number1()
Marking Error: Input string was not in a correct format.()
Marking Error: Input string was not in a correct format.()
Marking Error: Input string was not in a correct format.()
I looks like there is an issue with the message UID on most of the message. After this runs about 99% of the messages are not deleted, some 2-3 are deleted. If I re-run the program, i get the same errors but a few less and another 2-3 emails are deleted.
How am I supposed to delete emails with the Koolwired.Imap library?
Are there other Imap libraries that work with c#? When i was looking this is the only one that I found.
Your code looks like it should work according to http://imapnet.codeplex.com/Thread/View.aspx?ThreadId=73377 and I see you posted out there as well. Have you tried setting up a gmail account and testing it against that just to see what happens?
As for other libraries, I have used the EAGetMail POP3 & IMAP4 component (cannot add link due to my new account: www.emailarchitect.net/eagetmail/) on previous projects and had good luck with it.
How do I find out what's wrong with the device info set returned? I'm re-writing my code again and I'm still hitting the same stumbling block.
deviceInfoSet = SetupDiGetClassDevs(ref tGuid, 0, IntPtr.Zero, (uint)SetupDiFlags.DIGCF_PRESENT );
if (deviceInfoSet.ToInt32() == INVALID_DEVICE_HANDLE)
{
int errCode = Marshal.GetLastWin32Error();
errorMessage = new Win32Exception(Marshal.GetLastWin32Error()).Message;
statusLabel.Text += "Invalid deviceinfoset returned: " + errCode + " => " + errorMessage + ".";
}
The above code doesn't cause any errors but when I use the code below:
result = true;
while (result)
{
result = SetupDiEnumDeviceInterfaces(deviceInfoSet, IntPtr.Zero, ref tGuid, Index, ref anInterface);
if (!result)
{
int errCode = Marshal.GetLastWin32Error();
errorMessage = new Win32Exception(Marshal.GetLastWin32Error()).Message;
statusLabel.Text += "\nSetDiEnumDeviceInterface Error: " + errCode + " => " + errorMessage + ".";
break;
}
Index++;
}
to try and access the device info set list, error code 259 (No more data is available) is returned. I am at a loss as to what I'm doing wrong.
Are you sure you're using the right GUID?
Check out http://blogs.msdn.com/doronh/archive/2006/02/15/532679.aspx
Edit: Everything else looks by-the-book and correct.
Edit2: Trying including DIGCF_DEVICEINTERFACE in call to SetupDiGetClassDevs, and see if that works for you. That is, both DIGCF_PRESENT and DIGCF_DEVICEINTERFACE.
Edit3: For the 64bit issue (#Thies), check out http://social.msdn.microsoft.com/Forums/en-US/windowssdk/thread/ea816aea-f718-4a0e-b013-0aa273de037f
I'm not familiar with this particular interface but it doesn't appear you are doing anything wrong. It simply appears that you are trying to read data from a device which currently has no data to offer.
Is that the case? Do you know for sure that the device is currently trying to return data to you?
I had simular problems which were due to running on 64-bit Windows. I never quite figured it out, and ended up hardcoding the device path in my code - which is not recommended.
I think it has to do with the API structures not setup correct for 64-bit.
Hope this may help lead someone else to an answer (and maybe help with my problem as well)
Please state if you are running 64-bit - and have you tried the same code on a 32-bit OS?
The problem starts with how SetupDiGetClassDevs is called.
If you are looking to get a device path, use SetupDiGetClassDevs(&GUID_DEVINTERFACE_USB_DEVICE ,,,)
SetupDiEnumDeviceInterfaces fails with error 259 if SetupDiGetClassDevs is given the wrong GUID in ClassGuid which MS Help says is A pointer to the GUID for a device setup class or a device interface class.
Include file devguid.h contains a set of GUID_DEVCLASS values. These are NOT the same as GUID_DEVINTERFACE_* values which are the one you need.
Use #include which includes ksuuids.h where you'll find GUID_DEVINTERFACE_* values.
There's a more detailed explanation on my website, with some source code that should help in correctly enumerating USB devices.
See http://pixcl.com/SetupDiEnumInterfaces_Fail.htm