错误页面+闭合连接 [英] error page + close conection

查看:117
本文介绍了错误页面+闭合连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 发生错误时,我在关闭与SQL Server的连接时遇到问题
我的程序允许用户上传具有特定格式和特定​​标签名的excel文件,因为这是客户端发送的模板,但是众所周知,并非所有人都会使用该模板并将其以不正确的格式发送回,所以当我上传文件时,它会弹出错误页面.

我要做的步骤如下:
-browse,以便使用FileUpload上传excel文件,然后单击上传"(这将创建一个保存在其他位置的备份文件)
-尝试查看上传的文件(但是,如果文件格式错误或标签名称不正确,则会显示错误页面)
-i然后要做的是关闭浏览器,检查原始excel文档,然后尝试上载它,但是由于错误页面没有关闭连接,它说该文件是由其他人打开的.

显示错误页面时如何关闭连接?

我正在使用Visual Studio 2010和在VB中编程:-)

谢谢您的帮助.

Hi i am having an issue with closing the connection to my sql server when an error occurs
my program allows a user to upload an excel file with specific format and a specfific tab name, as this is the template sent out the the client, however as we all know not everyone will use the template and will send it back in the incorrect format, so when i go to upload the file it brings up and error page.

the steps i do are as follows:
-browse for the excel file to upload using FileUpload, and then click upload (this then creates a back up file saved in a different location)
-Attempt to view the file uploaded (however if the file is in the incorrect format or does not have the correct tab name an error page is presented)
-i then do is close the browsers, check the original excel document and then attempt to upload it, however as the error page does not close the connection it says that the file is open by someone else

how do i close the connection when the error page is displayed?

i am using Visual Studio 2010 and programming in VB :-)

thank you for your help

推荐答案

您好,我弄清楚了如何使用警报框关闭连接wooo hoo

但现在我遇到的问题是,当上传excel文件时,但是选项卡名称错误时,我不会显示错误警报框,但是如果上传的文件格式不正确(例如,列标题不正确)然后显示错误消息.

请在下面查看我的代码

hi so ive figured out how to close the connection using alert boxes wooo hoo

but now the issue i am having is that when the excel file is uploaded, but the tab name is wrong the error alert box i not displayed, however if the uploaded file is in the incorrect format (e.g the title of the columns is incorrect) then the error message is displayed.

please see my code below

Protected Sub ButtonView_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonView.Click
        importButtonEnabled = True
        PanelUpload.Visible = False
        PanelView.Visible = True
        PanelImport.Visible = False
        btnBack.Visible = True
        btnBack.Enabled = True
        Dim xConnstr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                          "Data Source=" & Server.MapPath("SiteTemplate.xls") & ";" & _
                          "Extended Properties=Excel 8.0"
        Dim objXConn As New OleDbConnection(xConnstr)


        Try

            objXConn.Open()

            Dim objCommand As New System.Data.OleDb.OleDbCommand("SELECT * FROM [importsites


" ,objXConn) Dim objDataAdapter As 新建 OleDbDataAdapter() objDataAdapter.SelectCommand = objCommand Dim objDataSet As New DataSet() objDataAdapter.Fill(objDataSet," ) ' 查看您在gridview中上传的数据.这将检查此时是否有空行,并在必要时更改颜色 GridView1.DataSource = objDataSet.Tables( 0 ).DefaultView GridView1.DataBind() ' 如果结束 objXConn.Close() ButtonImport.Enabled = importButtonEnabled 如果 ButtonImport.Enabled = 错误 然后 lblerror.ForeColor = Drawing.Color.Red lblerror.Text = " 结束 如果 捕获,例如 As 异常 Response.Write(" ) Response.Write(" & ex.Message.ToString& " ) Response.Write(" ) 如果 objXConn.State = ConnectionState.打开然后 objXConn.Close() 结束 如果 最后 结束 尝试 结束
", objXConn) Dim objDataAdapter As New OleDbDataAdapter() objDataAdapter.SelectCommand = objCommand Dim objDataSet As New DataSet() objDataAdapter.Fill(objDataSet, "xldata") 'view the data you have uploaded in your gridview. this will check for any empty rows at this point and change the colours if necessary GridView1.DataSource = objDataSet.Tables(0).DefaultView GridView1.DataBind() 'End If objXConn.Close() ButtonImport.Enabled = importButtonEnabled If ButtonImport.Enabled = False Then lblerror.ForeColor = Drawing.Color.Red lblerror.Text = "ERROR WITH FILE" End If Catch ex As Exception Response.Write("<script LANGUAGE=JavaScript type=""text/javascript"">") Response.Write("alert('" & ex.Message.ToString & "');") Response.Write("</script>") If objXConn.State = ConnectionState.Open Then objXConn.Close() End If Finally End Try End Sub


这篇关于错误页面+闭合连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆