मैं डेटाबेस से कुछ बाइनरी डेटा खींचने और उन्हें पीडीएफ फाइलों में लिखने की कोशिश कर रहा हूं। अधिकांश भाग के लिए, यह तैराकी के साथ चल रहा है, लेकिन डेटा की कभी-कभी पंक्ति एक विशेष त्रुटि फेंकने लगती है -टाइमआउट अपवाद SqlDataReader को बंद करने का कारण बनता है?
टाइमआउट समाप्त हो गया। ऑपरेशन पूरा होने से पहले समय समाप्ति अवधि समाप्त हो गई है या सर्वर प्रतिक्रिया नहीं दे रहा है।
ध्यान रखें, यह केवल कुछ पंक्तियों पर होता है, और कभी यादृच्छिक नहीं होता है। एक ही पंक्ति हमेशा अपवाद फेंक देते हैं। मुझे सच में यकीन नहीं है कि अपवाद क्यों फेंक दिया जा रहा है, लेकिन मैं उन पंक्तियों को छोड़ने के ठीक हूं जो समस्याएं पैदा करते हैं और आगे बढ़ते हैं। मेरी समस्या, हालांकि, यह है कि जब मैं अपवाद पकड़ता हूं और फिर अगली पंक्ति पर जाने की कोशिश करता हूं, तो मैं एक और अपवाद में चला जाता हूं -
अमान्यऑपरेशन अपवाद - कॉल करने का अमान्य प्रयास पाठक बंद होने पर पढ़ें।
क्या इसका मतलब यह है कि पाठक स्वचालित रूप से अपवाद में चला जाता है जैसे ही बंद हो जाता है? बिना किसी नाटक के अगली पंक्ति में आगे बढ़ने के बारे में मैं कैसे जाउंगा?
while (sdrReader.Read()) // Second exception happens here
{
try
{
byte[] byteData = new Byte[(sdrReader.GetBytes(0, 0, null, 0, int.MaxValue))]; // first exception happens here
sdrReader.GetBytes(0, 0, byteData, 0, byteData.Length);
string strOutputFileName = sdrReader.GetInt32(1).ToString() + ".pdf";
msMemoryStreams = new MemoryStream();
msMemoryStreams.Write(byteData, 0, byteData.Length);
byte[] byteArray = msMemoryStreams.ToArray();
msMemoryStreams.Flush();
msMemoryStreams.Close();
writeByteArrayToFile(byteData, txtFilesPath.Text + "\\" + strOutputFileName);
}
catch (Exception e)
{
Logger.Write("Document failed to convert: " + e.Message);
}
}
स्टैक ट्रेस, के रूप में अनुरोध -
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error)
at System.Data.SqlClient.TdsParserStateObject.ReadSni(DbAsyncResult asyncResult, TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParserStateObject.ReadNetworkPacket()
at System.Data.SqlClient.TdsParserStateObject.ReadBuffer()
at System.Data.SqlClient.TdsParserStateObject.ReadByteArray(Byte[] buff, Int32 offset, Int32 len)
at System.Data.SqlClient.TdsParser.ReadSqlValue(SqlBuffer value, SqlMetaDataPriv md, Int32 length, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.ReadColumnData()
at System.Data.SqlClient.SqlDataReader.ReadColumn(Int32 i, Boolean setTimeout)
at System.Data.SqlClient.SqlDataReader.GetSqlBinary(Int32 i)
at System.Data.SqlClient.SqlDataReader.GetBytesInternal(Int32 i, Int64 dataIndex, Byte[] buffer, Int32 bufferIndex, Int32 length)
at System.Data.SqlClient.SqlDataReader.GetBytes(Int32 i, Int64 dataIndex, Byte[] buffer, Int32 bufferIndex, Int32 length)
at Pdf2Rtf.Form1.Read() in F:\Code\Pdf2Rtf\Pdf2Rtf\Pdf2Rtf\Form1.cs:line 77
at Pdf2Rtf.Form1.btnRead_Click(Object sender, EventArgs e) in F:\Code\Pdf2Rtf\Pdf2Rtf\Pdf2Rtf\Form1.cs:line 24
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Pdf2Rtf.Program.Main() in F:\Code\Pdf2Rtf\Pdf2Rtf\Pdf2Rtf\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
यह पता चला है कि मुझे बस टाइमआउट को छोड़ना था (दिमाग, आपको, मुझे इसे लगभग 10 मिनट तक बढ़ा देना था)। कुछ दस्तावेज I मैं निकालना विशाल हूँ! धन्यवाद;) – Paulie