I have just developed, as an assignment , a small conventional website, commonly used for “Log in “purposes. User enters the UserID and password. User ID is compares from the customer Table, to verify, if the name already exists in database. If yes, he is directed to main page.
Else he is directed to newuser Register page , for providing personal information . This information is added in the database table as a new recordset.
The code in index.aspx.vb file is as under.
Imports System.Data.SqlClient Partial Class index Inherits System.Web.UI.Page Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load End sub Protected Sub Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Submit.Click Session("Name") = txtusername.Text Dim con As New SqlConnection(System.Configuration. ConfigurationManager.AppSettings("Zeedb")) Dim dr As SqlDataReader 'Dim StudentID As String Dim strSQL As String = "SELECT * FROM tblCustomer WHERE CustomerName = '" & txtusername.Text & "' and Password = '" & txtPassword.Text & "'" Dim cmdSQL As SqlCommand Try con.Open() cmdSQL = New SqlCommand(strSQL, con) cmdSQL.ExecuteNonQuery() dr = cmdSQL.ExecuteReader If dr.Read Then Response.Redirect("mainpage.aspx") Else Response.Redirect("index1.aspx") End If Catch ex As Exception lblError.Text = ex.Message Finally con.Close() End Try End Sub Protected Sub newuser_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles newuser.Click Response.Redirect("register.aspx") End Sub End Class
The Customers file resides in database named “Zeedb “at a Local SQL server in a different directory within the same machine. Web server used is Local Host built-in within the same machine.
The problem I am facing is that when I debug the system, the build up succeeds. However, when data is entered in text boxes (User Name and Password) I receive an error message:
“The ConnectionString property has not been initialized”
As tried to search on MSDN and Google, it seems to be a very common mistake, but I could not find the remedy. The reason of the fault could not be identified.
Please help me pointing out , where is the oversight, which I cannot locate.