User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 374,616 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,255 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 542 | Replies: 4
Reply
Join Date: Jan 2005
Posts: 5
Reputation: ABDUL HAYEE is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ABDUL HAYEE ABDUL HAYEE is offline Offline
Newbie Poster

String connection

  #1  
May 10th, 2008
Hello!
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.
Thanks.
Abdul Hayee.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Location: Bristol, UK
Posts: 1,122
Reputation: majestic0110 is on a distinguished road 
Rep Power: 3
Solved Threads: 46
majestic0110's Avatar
majestic0110 majestic0110 is offline Offline
Veteran Poster

Re: String connection

  #2  
May 11th, 2008
Hi there. Try adding this to your connection string as follows:

FROM

 Dim con As New  SqlConnection(System.Configuration. 						ConfigurationManager.AppSettings("Zeedb"))

TO
string con = (string) ConfigurationSettings.AppSettings["Zeedb"];

SqlConnection con= new SqlConnection(ConnectionString); 

I hope this helps, however I can make no promises as VB is not a language I have delved into all that much. Let us know how it goes. This line of code is where the connection string is initialized:

SqlConnection con= new SqlConnection(ConnectionString);

A connection string needs to be treated like any other object you use in your code, therefore it needs to be initialized before it can be used. Good luck!
Last edited by majestic0110 : May 11th, 2008 at 2:58 pm.
If you have a quality, be proud of it and let it define you. Add it to the world!
If you got your answer, please mark the thread as Solved. It saves time when people are looking to contribute threads or for answers!
Reply With Quote  
Join Date: May 2008
Posts: 2
Reputation: mkp007patel is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
mkp007patel mkp007patel is offline Offline
Newbie Poster

Re: String connection

  #3  
May 16th, 2008
Dear friend

any time if you get this type of problem like "The ConnectionString property has not been initialized" or any initalization exception ,pls check the in initialization of that object and class.

ConnectionString="address of sqlserver databse"
SqlConnection con= new SqlConnection(ConnectionString);
Reply With Quote  
Join Date: May 2008
Posts: 28
Reputation: sebastian3 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
sebastian3 sebastian3 is offline Offline
Light Poster

Re: String connection

  #4  
May 16th, 2008
I think the problem might be in converting Converting to String

Dim Conn As String = Convert.ToString(ConfigurationManager.AppSettings["xyz"]) 
Dim objConnection As New SqlConnection(Conn) 
objConnectiopn.Open()

It should work. If it doesn't then check your connection string properties.
Last edited by sebastian3 : May 16th, 2008 at 3:07 am. Reason: Organising format
Reply With Quote  
Join Date: May 2008
Location: India
Posts: 65
Reputation: sierrainfo is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
sierrainfo sierrainfo is offline Offline
Junior Poster in Training

Re: String connection

  #5  
May 17th, 2008
Just remove this Line:
cmdSQL.ExecuteNonQuery()
This is not required. ExecuteNonQuery is used for Insert, Update, Delete statements.

Regards
Sunil Punjabi
<URL Snipped>
Last edited by peter_budo : May 18th, 2008 at 4:27 am. Reason: Keep It Organized - please use [code] tags + Keep It Spam-Free - Do not spam, advertise, plug your website, or engage in any other type of self promotion.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb ASP.NET Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 8:57 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC