关于错误System.Data.dll中发生类型'System.Data.SqlClient.SqlException'的异常,但未在用户代码中处理

时间:2017-04-17 18:03:30

标签: c# sql asp.net

我是c#的初学者,当我执行我的代码时,它显示错误“System.Data.dll中发生类型'System.Data.SqlClient.SqlException'的异常,但未在用户代码中处理”。

其他信息:建立与SQL Server的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确以及SQL

这是我的代码:

public partial class _default:System.Web.UI.Page     {         protected void Page_Load(object sender,EventArgs e)         {             showdata();         }

===================================================================== 
'DIMENSIONING VARS AND PATHS
Dim Level As Range
Dim i, j, q(1 To 50) As Long
Dim numofchar As Long
Dim filepath As String
Dim filename As String
Dim PN As String
Dim HEADERrowcallout As Long
Dim LASTREQrowcallout As Long
Dim REQTEXTcolumncallout As String
Dim x As Long
Dim s As String
Dim count As Long
Dim Reqtext As Variant
Dim SectionText As Variant
'

'scanf(Input the correct row and column numbers). Used for determining start and endpoints of filtering files
HEADERrowcallout = InputBox("What row number are your headers in?")
LASTREQrowcallout = InputBox("What row number are your headers in?")
REQTEXTcolumncallout = InputBox("What is the column letter where ReqText is located? (A=1,B=2,D=4,ect...)")
'REQTYPEcolumncallout = InputBox("What is the column number from the left where the outline level is located? (A=1, B=2, ect...)")
'SECTIONcolumncallout = InputBox("What is the column number from the left where the outline level is located? (A=1, B=2, ect...)")
'


'stop screen updating
Application.ScreenUpdating = False
'

'show gridlines
ActiveWindow.DisplayGridlines = True
'

'Requirement Text to Section Maker --- Part (1)
'Part 1 filter string for the section number. (Numbers 1-10 & . until letters or space)
'Generate a string using the numbers and letters, ex [1.1.3.], cut & copy data to section column same row
For i = HEADERrowcallout + 1 To LASTREQrowcallout

    'Get length of active cell. This is max that copied cell will be

    LengthCell = Len(Cells(HEADERrowcallout + 1, REQTEXTcolumncallout))
    SectionText = (LengthActiveCell)
    Reqtext = (LengthActiveCell)

        'while count != length, scan each array position from 0 until array position value != 1-10 or .
        While x < LengthActiveCell
            Select Case Cells()
            Case "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "."
            Dim count As Long
            x = x + 1

        'If no more letters or .s, move to next cell
            x = LengthCell
    'if SectionText() = SectionText(0)

    'Keep going down ReqText column until specified end
    HEADERrowcallout = HEADERrowcallout + 1


End Sub
===========================

2 个答案:

答案 0 :(得分:0)

您的cmd命令不正确。

变化

SqlCommand cmd = new SqlCommand("select * from demo, con");

SqlCommand cmd = new SqlCommand("select * from demo", con);

答案 1 :(得分:0)

感谢您的帮助,我也很感激。我从朋友那里得到了答案,我的查询中有一个@缺失。

SqlConnection con = new SqlConnection(@“server = demo; database = demo; Integrated Security = True;”);

更新后,我能够在浏览器上看到我的数据。

但再次感谢大家的帮助。