Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB ASP.NET Homework
Hello guys, first of all I would like to say my thanks to all for your help. Now I am facing another problem. My Instructor wanted me to use Microsoft SQL Server 2005. The problem is I don't know how to use it please help me.
Here is my trial code:
<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Web.UI" %>
 
<script language="VB" runat="server">
 
    Sub btnLogin_OnClick(Src As Object, E As EventArgs)
        Dim strSQL As String
        Dim myCommand As OleDbCommand
        Dim strUserURL As String
        Using connection As New OleDbConnection("datasource1")
            strSQL = "SELECT * FROM [Admin] " _
            & "WHERE LogName='" & Replace(txtUsername.Text, "'", "''") & "' " _
            & "AND LogPass='" & Replace(txtPassword.Text, "'", "''") & "'"
            myCommand = New OleDbCommand(strSQL, connection)
            connection.Open()
            strUserURL = myCommand.ExecuteScalar()
            connection.Close()
 
            If strUserURL <> "" Then
                lblInvalid.Text = ""
                FormsAuthentication.SetAuthCookie(txtUsername.Text, True)
                Response.Redirect("bob.aspx")
            Else
                lblInvalid.Text = "Sorry... try again..."
            End If
 
        End Using
    End Sub
 

</script>
 
<html>
<head>
<title>ASP.NET Login</title>
</head>
<body>
 
<h2>Please Login:</h2>
 
<p>
<asp:Label id="lblInvalid" runat="server" />
</p>
 
<form runat="server">
 
    Username: <asp:TextBox id="txtUsername" runat="server" /><br />
    Password: <asp:TextBox id="txtPassword" TextMode="password" runat="server" Width="155px" /><br />
    <br />
    position: &nbsp;&nbsp;
    <asp:TextBox id="items" runat="server" /><br />
    <br />
    <br />
    <asp:Button id="btnLogin" runat="server"
        text="Login" OnClick="btnLogin_OnClick" Width="221px"
    />&nbsp;
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TestSQLConnectionString %>"
        SelectCommand="SELECT * FROM [Admin]" OnSelecting="SqlDataSource1_Selecting"></asp:SqlDataSource>
</form>
 
</body>
</html>
 
Here is the web.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 
    <!-- enable forms authentication -->
    <system.web>
        <authentication mode="Forms">
            <forms name="ASP101SampleAuth" loginUrl="login_db_nav.aspx" />
        </authentication>
    </system.web>
 
    <!-- set secure page to reject anonymous users -->
    <location path="bob.aspx">
        <system.web>
            <authorization>
                <allow users="*" />
                <deny users="none" />
            </authorization>
        </system.web>
    </location>
 

</configuration>
 
Now here is the error I'm trying to debug:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
 
Compiler Error Message: BC30456: 'SqlDataSource1_Selecting' is not a member of 'ASP.login_db_nav_aspx'.
 
Source Error:
 

 
Line 57:        text="Login" OnClick="btnLogin_OnClick" Width="221px"
Line 58:    />&nbsp;
Line 59:     <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TestSQLConnectionString %>"
Line 60:         SelectCommand="SELECT * FROM [Admin]" OnSelecting="SqlDataSource1_Selecting"></asp:SqlDataSource>
Line 61: </form>
 

Source File: C:\Documents and Settings\oca14625\Desktop\login_db_nav.aspx    Line: 59
 

Please help me.. I don't know where I got it wrong..
Posted 26-Apr-11 21:09pm
Edited 26-Apr-11 22:53pm
v5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
Please go through with the article
Connect to SQL Server Using SQL Authentication in ASP.NET 2.0
 
Please check Connection String syntax from this site.
Connection Strings
 
Regards
AR
  Permalink  
v2
Comments
drkterror1 at 27-Apr-11 2:43am
   
Thanks reading it ^_^
Ramalinga Koushik at 28-Jun-11 2:30am
   
Good Call. My 5 too.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I know that my code is in logical error. I know that I still have to learn more. But my main problem is even I follow the instruction the problem is still the same here is what I did:
web.config
<pre lang="xml"><?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <connectionStrings>
    <add name="connection" connectionstring="Server=TestSQLConnectionString"; database="pubs"; userID="MyUser"; password="password"
         providerName="System.Data.SqlClient"/>
 
  </connectionStrings>
    <!-- enable forms authentication -->
    <system.web>
        <authentication mode="Forms">
            <forms name="ASP101SampleAuth" loginUrl="login_db_nav.aspx" />
        </authentication>
    </system.web>
 
    <!-- set secure page to reject anonymous users -->
    <location path="bob.aspx">
        <system.web>
            <authorization>
                <allow users="*" />
                <deny users="none" />
            </authorization>
        </system.web>
    </location>
 

 
</configuration>
 
Is there any wrong in my codes?
Plss help any suggestion is appreciated
  Permalink  
Comments
Ankit Rajput at 27-Apr-11 3:05am
   
I think, problem is occuring due to Connection String.
 
I am updating my answer for Connection String purpose.
Ankit Rajput at 27-Apr-11 3:06am
   
Please mention the error you are getting.
It will help everyone to think about your problem.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

<pre lang="msil">Server Error in '/Desktop' Application.
--------------------------------------------------------------------------------
 
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
 
Compiler Error Message: BC30456: 'SqlDataSource1_Selecting' is not a member of 'ASP.login_db_nav_aspx'.

Source Error:
 

 
Line 57:        text="Login" OnClick="btnLogin_OnClick" Width="221px"
Line 58:    />&nbsp;
Line 59:     <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TestSQLConnectionString %>"
Line 60:         SelectCommand="SELECT * FROM [Admin]" OnSelecting="SqlDataSource1_Selecting"></asp:SqlDataSource>
Line 61: </form>
 

Source File: C:\Documents and Settings\oca14625\Desktop\login_db_nav.aspx    Line: 59
 

 
Show Detailed Compiler Output:
 

C:\Program Files\Microsoft Visual Studio 8\Common7\IDE>
Here is the error
  Permalink  
Comments
Ankit Rajput at 27-Apr-11 3:19am
   
Have you defind this function(SqlDataSource1_Selecting' ) in your code behind or any where else
drkterror1 at 27-Apr-11 3:25am
   
I add a SqlDatasource and configure it to connect to my login.asp
drkterror1 at 27-Apr-11 3:26am
   
I think my problem is OleDB.. Is Oledb reliable when you are using SQLserver?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Looks like you have problem with your query string...Try like this..Just replace the below line in config file
<add name="connection" connectionstring="Server=TestSQLConnectionString; database=pubs; userID=MyUser; password=password" providername="System.Data.SqlClient" />
  Permalink  
Comments
Ankit Rajput at 27-Apr-11 3:18am
   
this is one also will not work
Ankit Rajput at 27-Apr-11 3:18am
   
Server=TestSQLConnectionString; database=pubs; user ID=MyUser; password=password
drkterror1 at 27-Apr-11 3:28am
   
Data Source=ML0003135586;Initial Catalog=TestSQL;Integrated Security=True
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Sir ive manipulated some of my codes
here is what i did:

Using connection As New OleDbConnection("Provider=.NET Framework Data Provider for SQL Server; " _
& "Data Source=ML0003135586" & Server.MapPath("Admin") & ";")
strSQL = "SELECT * FROM [Admin] " _
& "WHERE LogName='" & Replace(txtUsername.Text, "'", "''") & "' " _
& "AND LogPass='" & Replace(txtPassword.Text, "'", "''") & "'"
myCommand = New OleDbCommand(strSQL, connection)
connection.Open()
strUserURL = myCommand.ExecuteScalar()
connection.Close()

 
Now the problem look like this:

The '.NET Framework Data Provider for SQL Server' provider is not registered on the local machine.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The '.NET Framework Data Provider for SQL Server' provider is not registered on the local machine.
Source Error:
 
Line 16: & "AND LogPass='" & Replace(txtPassword.Text, "'", "''") & "'"
Line 17: myCommand = New OleDbCommand(strSQL, connection)
Line 18: connection.Open()
Line 19: strUserURL = myCommand.ExecuteScalar()
Line 20: connection.Close()

Source File: C:\Documents and Settings\oca14625\Desktop\login_db_nav.aspx Line: 18
Stack Trace:
 
[InvalidOperationException: The '.NET Framework Data Provider for SQL Server' provider is not registered on the local machine.]
System.Data.OleDb.OleDbServicesWrapper.GetDataSource(OleDbConnectionString constr, DataSourceWrapper& datasrcWrapper) +963332
System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) +124
System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) +86
System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) +29
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +4863644
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117
System.Data.OleDb.OleDbConnection.Open() +40
ASP.login_db_nav_aspx.btnLogin_OnClick(Object Src, EventArgs E) in C:\Documents and Settings\oca14625\Desktop\login_db_nav.aspx:18
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

 
  Permalink  
Comments
Ankit Rajput at 27-Apr-11 3:47am
   
Now check your connection string.
I have already mentioned the link in my Answer
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

Ive got it....
Thank you all for your help
<pre lang="xml"><%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Web.UI" %>
 
<script language="VB" runat="server">
 
    Sub btnLogin_OnClick(Src As Object, E As EventArgs)
        Dim strSQL As String
        Dim strUserURL As String
        Dim connection As SqlClient.SqlConnection = New SqlClient.SqlConnection("Data Source=ML0003135586;Integrated Security=SSPI;" & "Initial Catalog=TestSQL")
        strSQL = "SELECT * FROM [tblLog] " _
        & "WHERE LogName='" & Replace(txtUsername.Text, "'", "''") & "' " _
        & "AND LogPass='" & Replace(txtPassword.Text, "'", "''") & "'"
        connection.Open()
        Dim myCommand As SqlClient.SqlCommand = New SqlClient.SqlCommand(strSQL, connection)
        strUserURL = myCommand.ExecuteScalar()
 
        If strUserURL <> "" Then
            lblInvalid.Text = ""
            FormsAuthentication.SetAuthCookie(txtUsername.Text, True)
            Response.Redirect("bob.aspx")
        Else
            lblInvalid.Text = "Sorry... try again..."
        End If
 

    End Sub
    '("Data Source=ML0003135586;Integrated Security=SSPI;" & "Initial Catalog=TestSQL")
    'Data Source=ML0003135586;Initial Catalog=TestSQL;Integrated Security=True
</script>
 
<html>
<head>
<title>ASP.NET Login</title>
</head>
<body>
 
<h2>Please Login:</h2>
 
<p>
<asp:Label id="lblInvalid" runat="server" />
</p>
 
<form id="Form1" runat="server">
 
    Username: <asp:TextBox id="txtUsername" runat="server" /><br />
    Password: <asp:TextBox id="txtPassword" TextMode="password" runat="server" Width="155px" /><br />
    <br />
    position: &nbsp;&nbsp;
    <asp:TextBox id="items" runat="server" /><br />
    <br />
    <br />
    <asp:Button id="btnLogin" runat="server"
        text="Login" OnClick="btnLogin_OnClick" Width="221px"
    />&nbsp;&nbsp;
</form>
 

</body>
</html>
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

please send sql connectivity example in asp .net
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 8

TRY THIS
 
<pre lang="xml"><%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Web.UI" %>
 
<script language="VB" runat="server">
 
    Sub btnLogin_OnClick(Src As Object, E As EventArgs)
        Dim strSQL As String
        Dim strUserURL As String
        Dim connection As SqlClient.SqlConnection = New SqlClient.SqlConnection("Data Source=ML0003135586;Integrated Security=SSPI;" & "Initial Catalog=TestSQL")
        strSQL = "SELECT * FROM [tblLog] " _
        & "WHERE LogName='" & Replace(txtUsername.Text, "'", "''") & "' " _
        & "AND LogPass='" & Replace(txtPassword.Text, "'", "''") & "'"
        connection.Open()
        Dim myCommand As SqlClient.SqlCommand = New SqlClient.SqlCommand(strSQL, connection)
        strUserURL = myCommand.ExecuteScalar()
 
        If strUserURL <> "" Then
            lblInvalid.Text = ""
            FormsAuthentication.SetAuthCookie(txtUsername.Text, True)
            Response.Redirect("bob.aspx")
        Else
            lblInvalid.Text = "Sorry... try again..."
        End If
 

    End Sub
    '("Data Source=ML0003135586;Integrated Security=SSPI;" & "Initial Catalog=TestSQL")
    'Data Source=ML0003135586;Initial Catalog=TestSQL;Integrated Security=True
</script>
 
<html>
<head>
<title>ASP.NET Login</title>
</head>
<body>
 
<h2>Please Login:</h2>
 
<p>
<asp:Label id="lblInvalid" runat="server" />
</p>
 
<form id="Form1" runat="server">
 
    Username: <asp:TextBox id="txtUsername" runat="server" /><br />
    Password: <asp:TextBox id="txtPassword" TextMode="password" runat="server" Width="155px" /><br />
    <br />
    position:
    <asp:TextBox id="items" runat="server" /><br />
    <br />
    <br />
    <asp:Button id="btnLogin" runat="server"
        text="Login" OnClick="btnLogin_OnClick" Width="221px"
    />
</form>
 

</body>
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 485
1 OriginalGriff 310
2 Shweta N Mishra 244
3 Mathew Soji 225
4 BillWoodruff 200
0 OriginalGriff 6,153
1 Sergey Alexandrovich Kryukov 5,758
2 DamithSL 4,958
3 Manas Bhardwaj 4,539
4 Maciej Los 3,735


Advertise | Privacy | Mobile
Web03 | 2.8.1411019.1 | Last Updated 28 Jun 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100