Using ASP.NET to login to SQL Server 2005 Database

Hi,
I am running the following configuration:
Windows Server 2003 Enterprise Edition SP2
ASP.NET 2.0
SQL Server 2005

I currently have a website in IIS that has ASP.NET enabled. I have a
login.aspx page which has the login box with the username and
password. When I click the login box, I want asp.net to check the SQL
database to check if the username and password are valid, and then
continue to a destination page. However, I receive an error when I
click Login.

------------------------------------------------------------ -------------------------------------------------------
An error has occurred while establishing a connection to the server.
When connecting to SQL Server 2005, this failure may be caused by the
fact that under the default settings SQL Server does not allow remote
connections. (provider: SQL Network Interfaces, error: 26 - Error
Locating Server/Instance Specified)

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.

Stack Trace:

[SqlException (0x80131904): An error has occurred while establishing a
connection to the server. When connecting to SQL Server 2005, this
failure may be caused by the fact that under the default settings SQL
Server does not allow remote connections. (provider: SQL Network
Interfaces, error: 26 - Error Locating Server/Instance Specified)]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlExcep tion
exception, Boolean breakConnection) +734979

System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(Tds ParserStateObject
stateObj) +188
System.Data.SqlClient.TdsParser.Connect(Boolean&
useFailoverPartner, Boolean& failoverDemandDone, String host, String
failoverPartner, String protocol, SqlInternalConnectionTds
connHandler, Int64 timerExpire, Boolean encrypt, Boolean
trustServerCert, Boolean integratedSecurity, SqlConnection
owningObject, Boolean aliasLookup) +820

System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnli st(SqlConnection
owningObject, SqlConnectionString connectionOptions, String
newPassword, Boolean redirectedUserInstance) +628

System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConne ctionPoolIdentity
identity, SqlConnectionString connectionOptions, Object providerInfo,
String newPassword, SqlConnection owningObject, Boolean
redirectedUserInstance) +170

System.Data.SqlClient.SqlConnectionFactory.CreateConnection( DbConnectionOptions
options, Object poolGroupProviderInfo, DbConnectionPool pool,
DbConnection owningConnection) +359

System.Data.ProviderBase.DbConnectionFactory.CreatePooledCon nection(DbConnection
owningConnection, DbConnectionPool pool, DbConnectionOptions options)
+28
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbCon nection
owningObject) +424

System.Data.ProviderBase.DbConnectionPool.UserCreateRequest( DbConnection
owningObject) +66

System.Data.ProviderBase.DbConnectionPool.GetConnection(DbCo nnection
owningObject) +496

System.Data.ProviderBase.DbConnectionFactory.GetConnection(D bConnection
owningConnection) +82

System.Data.ProviderBase.DbConnectionClosed.OpenConnection(D bConnection
outerConnection, DbConnectionFactory connectionFactory) +105
System.Data.SqlClient.SqlConnection.Open() +111
System.Web.DataAccess.SqlConnectionHolder.Open(HttpContext context,
Boolean revertImpersonate) +84
System.Web.DataAccess.SqlConnectionHelper.GetConnection(Stri ng
connectionString, Boolean revertImpersonation) +197

System.Web.Security.SqlMembershipProvider.GetPasswordWithFor mat(String
username, Boolean updateLastLoginActivityDate, Int32& status, String&
password, Int32& passwordFormat, String& passwordSalt, Int32&
failedPasswordAttemptCount, Int32& failedPasswordAnswerAttemptCount,
Boolean& isApproved, DateTime& lastLoginDate, DateTime&
lastActivityDate) +1121
System.Web.Security.SqlMembershipProvider.CheckPassword(Stri ng
username, String password, Boolean updateLastLoginActivityDate,
Boolean failIfNotApproved, String& salt, Int32& passwordFormat) +105
System.Web.Security.SqlMembershipProvider.CheckPassword(Stri ng
username, String password, Boolean updateLastLoginActivityDate,
Boolean failIfNotApproved) +42
System.Web.Security.SqlMembershipProvider.ValidateUser(Strin g
username, String password) +83

System.Web.UI.WebControls.Login.OnAuthenticate(AuthenticateE ventArgs
e) +160
System.Web.UI.WebControls.Login.AttemptLogin() +105
System.Web.UI.WebControls.Login.OnBubbleEvent(Object source,
EventArgs e) +99
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs
args) +35
System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +115
System.Web.UI.WebControls.Button.RaisePostBackEvent(String
eventArgument) +163

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEven tHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
+33
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+5102

------------------------------------------------------------ --------------------------------------------------

I have tried to do the following, but to no avail. I went into the SQL
Server Management Studio and right clicked on the server, and selected
Properties. I then went under Connections and made sure "Allow Remote
Connections to this server" was enabled. I also setup in SQL Service
Area Configuration to enable both Local and TCP/IP protocols. In IIS,
I have the database string for SQL as the following:
Data Source=.\MSSQLSERVER2005;Initial Catalog=aspnetdb.mdf;Integrated
Security=True

I am not sure what else to try. Am I missing something here?
AMD_GAMER [ Mi, 19 September 2007 05:42 ] [ ID #1824109 ]

Re: Using ASP.NET to login to SQL Server 2005 Database

AMD_GAMER (amdgamer18 [at] gmail.com) writes:
> I am running the following configuration:
> Windows Server 2003 Enterprise Edition SP2
> ASP.NET 2.0
> SQL Server 2005
>
> I currently have a website in IIS that has ASP.NET enabled. I have a
> login.aspx page which has the login box with the username and
> password. When I click the login box, I want asp.net to check the SQL
> database to check if the username and password are valid, and then
> continue to a destination page. However, I receive an error when I
> click Login.
>...
> I have tried to do the following, but to no avail. I went into the SQL
> Server Management Studio and right clicked on the server, and selected
> Properties. I then went under Connections and made sure "Allow Remote
> Connections to this server" was enabled. I also setup in SQL Service
> Area Configuration to enable both Local and TCP/IP protocols. In IIS,
> I have the database string for SQL as the following:
> Data Source=.\MSSQLSERVER2005;Initial Catalog=aspnetdb.mdf;Integrated
> Security=True

So SQL Server is running on the same machine as IIS? (I don't think this is
a recommended setup, by the way).

When you connect to the server in SSMS do you specify .\MSSQLSERVER2005 as
well? That is, is SQL Server installed as a named instance?

Furthermore, is your database really called "aspnetdb.mdf"? That is not
causing any problem at this stage, but it could be the next road block
once you make into the server.


--
Erland Sommarskog, SQL Server MVP, esquel [at] sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downlo ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books .mspx
Erland Sommarskog [ Mi, 19 September 2007 09:31 ] [ ID #1824111 ]

Re: Using ASP.NET to login to SQL Server 2005 Database

Hi,
I got it setup. I think part of the problem was in the web.config
file. Also, I think there was a permissions problem with the database.
In any event, its working flawlessly now.
AMD_GAMER [ Fr, 21 September 2007 04:04 ] [ ID #1826096 ]
Datenbanken » comp.databases.ms-sqlserver » Using ASP.NET to login to SQL Server 2005 Database

Vorheriges Thema: How to select count records that "contain" data?
Nächstes Thema: CREATE Table permission