将Sql Server 2005连接到ASP.net [英] Connecting Sql Server 2005 to ASP.net
问题描述
大家好,首先,我要感谢大家的帮助.现在,我面临另一个问题.我的讲师希望我使用Microsoft SQL Server2005.问题是我不知道如何使用它,请帮助我.
这是我的试用代码:
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:
<asp:TextBox id="items" runat="server" /><br />
<br />
<br />
<asp:Button id="btnLogin" runat="server"
text="Login" OnClick="btnLogin_OnClick" Width="221px"
/>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TestSQLConnectionString %>"
SelectCommand="SELECT * FROM [Admin]" OnSelecting="SqlDataSource1_Selecting"></asp:SqlDataSource>
</form>
</body>
</html>
这是web.config:
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: />
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..
推荐答案
ConnectionStrings:TestSQLConnectionString %> ; " SelectCommand =" 选择*来自[管理员]" OnSelecting =" > < > < /form > < /body > < /html >
ConnectionStrings:TestSQLConnectionString %>" SelectCommand="SELECT * FROM [Admin]" OnSelecting="SqlDataSource1_Selecting"></asp:SqlDataSource> </form> </body> </html>
这是web.config:
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: />
Line 59: <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%
ConnectionStrings:TestSQLConnectionString%>" 第60行:SelectCommand ="SELECT * FROM [Admin]" OnSelecting ="SqlDataSource1_Selecting"></asp:SqlDataSource> 第61行:</form> 源文件:C:\ Documents and Settings \ oca14625 \ Desktop \ login_db_nav.aspx行:59
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..
请仔细阅读文章
使用ASP.NET 2.0中的SQL身份验证连接到SQL Server
请从此站点检查连接字符串语法.
连接字符串
问候
AR
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
这篇关于将Sql Server 2005连接到ASP.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!