•
•
•
•
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
![]() |
•
•
Join Date: Jan 2005
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
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.
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.
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 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.
•
•
Join Date: Oct 2007
Location: Bristol, UK
Posts: 1,122
Reputation:
Rep Power: 3
Solved Threads: 46
Hi there. Try adding this to your connection string as follows:
FROM
TO
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:
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!
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!
If you got your answer, please mark the thread as Solved. It saves time when people are looking to contribute threads or for answers!
•
•
Join Date: May 2008
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
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);
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);
•
•
Join Date: May 2008
Posts: 28
Reputation:
Rep Power: 1
Solved Threads: 1
I think the problem might be in converting Converting to String
It should work. If it doesn't then check your connection string properties.
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
•
•
Join Date: May 2008
Location: India
Posts: 65
Reputation:
Rep Power: 1
Solved Threads: 2
Just remove this Line:
This is not required. ExecuteNonQuery is used for Insert, Update, Delete statements.
Regards
Sunil Punjabi
<URL Snipped>
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.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb ASP.NET Marketplace
- Simple ASP.Net Login Page (Using VB.Net) (ASP.NET)
- JDBC connection (Java)
- string translation (Java)
- SQL not a trusted connection?! (ASP.NET)
- JDBC connection (Java)
Other Threads in the ASP.NET Forum
- Previous Thread: .Net Web Application Deployment Problem On Windows Vista
- Next Thread: Sending & Receiving Values



Linear Mode