WEB CONFIG and user auth. HELP plz

xssxss

New Member
Hi before all I must warn you that I'm actually a newbye in all related to ASP.NET. <BR>I've followed a wonderfull article from Scott Mitchell called "Specifying configuration Settings in Web.config. Well I'm using the Web Matrix prog. to develop my own web app. while learning ASP.NET. <BR><BR>I've got a User control for the users to sign, well the connection string I use to connect to the database is like this: <BR><BR>Dim connectionString As String = ConfigurationSettings.AppSettings("sap4all") <BR><BR>My Web.config configuration is: <BR><BR><configuration> <BR><BR><BR><appSettings> <BR><!-- The value parameter is all writed at the same line --> <BR><add key="sap4all" value=http://aspmessageboard.com/archive/index.php/"server='localhost'; trusted_connection=true; Database='SAP4all'" /> <BR></appSettings> <BR><BR><system.web> <BR><BR><BR><authentication mode="Forms"> <BR><forms name=".ASPXAUTH" loginUrl="main.aspx" /> <BR></authentication> <BR><BR><authorization> <BR><deny users="?" /> <BR></authorization> <BR><BR><compilation debug="true"/> <BR><BR></system.web> <BR><BR></configuration> <BR><BR>When I run the main.aspx page with the Web Matrix it only works the firs time, I mean if I test another page such a register.aspx page or whatever, and then I run the main.aspx again I get the following error message: <BR><BR>No se ha inicializado la propiedad ConnectionString. <BR>This could be something like: <BR>--The ConnectionString property was not initialized... <BR><BR>Detalles de la excepción: System.InvalidOperationException: No se ha inicializado la propiedad ConnectionString. <BR>--Exception details: System.InvalidOperationException: The connectionString property was not initialized <BR><BR><BR>Error de código fuente: <BR>--source code Error <BR><BR><BR>L?nea 20: Dim dataAdapter As System.Data.SqlClient.SqlDataAdapter = New System.Data.SqlClient.SqlDataAdapter(sqlCommand) <BR>L?nea 21: Dim dataSet As System.Data.DataSet = New System.Data.DataSet <BR>L?nea 22: dataAdapter.Fill(dataSet) <BR>L?nea 23: <BR>L?nea 24: Return dataSet <BR><BR><BR>Below is the three pages involved with it's entire source code.<BR><BR>The actual situation of the files in the wwwroot is the following: <BR>/wwwroot: <BR>web.config <BR> /sap4all/ <BR> main.asp <BR> /userControls/ <BR> log.ascx <BR><BR><BR>a).............WEB.CONFIG <BR><BR><?xml version="1.0" encoding="UTF-8" ?> <BR><BR><configuration> <BR><BR><BR><appSettings> <BR><add key="sap4all" value="server='localhost'; trusted_connection=true; Database='SAP4all'" /> <BR></appSettings> <BR><BR><BR><BR><system.web> <BR><BR><BR><BR><authentication mode="Forms"> <BR><forms name=".ASPXAUTH" loginUrl="main.aspx" /> <BR></authentication> <BR><BR><authorization> <BR><deny users="?" /> <BR></authorization> <BR><BR><compilation debug="true"/> <BR><BR></system.web> <BR><BR></configuration> <BR><BR><BR>b)............ MAIN.ASPX <BR><BR><%@ Page Language="VB" Debug="true" %> <BR><%@ Register TagPrefix="rubs" TagName="Log" Src="/UserControls/Log.ascx" %> <BR><%@ import Namespace="System.Configuration" %> <BR><script runat="server"> <BR><BR>Sub Page_Load(Sender as object, e as eventArgs) <BR><BR><BR>end sub <BR><BR></script> <BR><html> <BR><head> <BR><title>SAP4all --- Bienvenido ----</title> <BR><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <BR></head> <BR><body leftmargin="0" topmargin="0"> <BR><form runat="server"> <BR><table cellspacing="0" cellpadding="0" width="100%"> <BR><tbody> <BR><tr> <BR><td> <BR> </td> <BR></tr> <BR></tbody> <BR></table> <BR><table id="cont_ppal" cellspacing="0" cellpadding="0" width="100%"> <BR><tbody> <BR><tr> <BR><td> <BR> <BR><rubs:Log id="UserControl1" runat="server"></rubs:Log> <BR></td> <BR><td> <BR> <BR></td> <BR></tr> <BR></tbody> <BR></table> <BR></form> <BR></body> <BR></html> <BR><BR>c)........... LOG.ASCX <BR><BR><%@ Control Language="VB" Debug="true" %> <BR><%@ import Namespace="System.Configuration" %> <BR><%@ import Namespace="System.Data" %> <BR><%@ import Namespace="System.Data.SqlClient" %> <BR><script runat="server"> <BR><BR>Function GetUsers(ByVal user_id As String, ByVal password As String) As System.Data.DataSet <BR><BR>'Dim connectionString As String = "server='localhost'; trusted_connection=true; Database='SAP4all'" <BR>'Dim connectionString As String = ConfigurationSettings.GetConfig("Sap4allAppSettings")("connString") <BR>Dim connectionString As String = ConfigurationSettings.AppSettings("sap4all") <BR>Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(connectionStri ng) <BR><BR>Dim queryString As String = "SELECT [Users].* FROM [Users] WHERE (([Users].[User_id] = @User_id) AND ([Users]."& _ <BR>"[Password] = @Password))" <BR>Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection) <BR><BR>sqlCommand.Parameters.Add("@User_id", System.Data.SqlDbType.Char).Value = user_id <BR>sqlCommand.Parameters.Add("@Password", System.Data.SqlDbType.Char).Value = password <BR><BR>Dim dataAdapter As System.Data.SqlClient.SqlDataAdapter = New System.Data.SqlClient.SqlDataAdapter(sqlCommand) <BR>Dim dataSet As System.Data.DataSet = New System.Data.DataSet <BR>sqlConnection.open() <BR>dataAdapter.Fill(dataSet) <BR><BR>Return dataSet <BR><BR>End Function <BR><BR>Sub LoginBtn_Click(Sender As Object, E As EventArgs) <BR><BR>If Page.IsValid Then <BR><BR>Dim Users as New system.Data.Dataset <BR><BR>Users = GetUsers(Username.text, UserPass.Text) <BR><BR>If Users.Tables(0).Rows.Count = 1 Then <BR>'FormsAuthentication.RedirectFromLoginPage(UserNam e.Text, true) <BR>Msg.Text = "Usuario aceptado"' & Users.Tables(0).Columns(1).ToString() <BR>Else <BR>Msg.Text = "Usuario o Password incorrectos" <BR>Creausuario.Visible = true <BR>End If <BR>End If <BR><BR>End Sub <BR><BR></script> <BR><h2>Login Page <BR></h2> <BR><hr size="1" /> <BR><table> <BR><tbody> <BR><tr> <BR><td> <BR>Username:</td> <BR><td> <BR><asp:TextBox id="UserName" runat="server"></asp:TextBox> <BR></td> <BR><td> <BR><asp:RequiredFieldValidator id="Requiredfieldvalidator1" runat="server" ControlToValidate="UserName" Display="Static" ErrorMessage="*"></asp:RequiredFieldValidator> <BR></td> <BR></tr> <BR><tr> <BR><td> <BR>Password:</td> <BR><td> <BR><asp:TextBox id="UserPass" runat="server" TextMode="Password"></asp:TextBox> <BR></td> <BR><td> <BR><asp:RequiredFieldValidator id="Requiredfieldvalidator2" runat="server" ControlToValidate="UserPass" Display="Static" ErrorMessage="*"></asp:RequiredFieldValidator> <BR></td> <BR></tr> <BR></tbody> <BR></table> <BR><asp:button id="LoginBtn" onclick="LoginBtn_Click" runat="server" text="Login"></asp:button> <BR><p> <BR><asp:Label id="Msg" runat="server" ForeColor="red"></asp:Label> <BR></p> <BR><p> <BR><asp:HyperLink id="CreaUsuario" runat="server" Visible="False">Crear Usuario</asp:HyperLink> <BR></p> <BR><BR><BR>Hope I don`t forget anything <BR>Thanks for your coolaboration
 
Back
Top