2015-12-01 19 views
0

「SQLConn()。Open()」正在標記錯誤「Class'System.Data.SqlClient.SqlConnection'無法被索引,因爲它沒有默認屬性。」我很困惑,因爲我在其他(工作)文件中使用完全相同的語法。建議感激。謝謝SQLConn類錯誤

Using SQLConn = New SqlConnection(ConfigurationManager.ConnectionStrings("DataConnectionRemoteSQL").ConnectionString) 


      Try 
       SQLConn().Open() 

       Using cmd = New SqlCommand() 
        cmd.Connection = SQLConn 
        cmd.CommandText = "Select_UserLoginData" 
        cmd.CommandType = CommandType.StoredProcedure 
        param1 = cmd.Parameters.AddWithValue("@usern", username_s) 
        param1.Direction = ParameterDirection.Input 
        param1.DbType = DbType.String 


        Using user_rs = cmd.ExecuteReader() 

         If user_rs.Read() Then 


          'Create hash of plain text password entered 
          hashedpassword_s = s_CreateHash(password_s, user_rs("Salt")) 

          'If this password doesn't match what's stored in the database 
          If Not hashedpassword_s = user_rs("Hashed") Then 
           lbl_ErrorPanelText.Text = "Incorrect login credentials!" 
           pn_ErrorPanel.Visible = True 

          Else 
           Session("check") = 1 
           user_rs.Close() 
           Response.Redirect("menu.aspx", False) 
          End If 

         Else 
          lbl_ErrorPanelText.Text = "Incorrect login credentials!" 
          pn_ErrorPanel.Visible = True 
         End If 

        End Using 

       End Using 


      Catch ex As Exception 

       lbl_ErrorPanelText.Text = "Error establishing a database connection!" 
       pn_ErrorPanel.Visible = True 

      End Try 
     End Using 

回答

4

您在SQLConn後面有一個不必要的一組空括號。更改爲SQLConn.Open()並且此特定問題將消失。

通常,局部變量後面的括號表示「默認屬性」/索引器訪問(即通過數字索引訪問數組中的元素),因此是錯誤消息。