Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: Need Help Connecting to a SQL Database


Message #1 by "Roger Finks" <rfinks01@e...> on Tue, 4 Feb 2003 12:10:56
I've used the sql_connect.aspx program from Chapter 12 of Beginning 
ASP.NET 1.0 to connect to an MSDE SQL database "northwind" that was 
created by .NET Quickstarts, Tutorials and Samples. I was able to connect 
okay. 

I then created a new database using Visual Studio .NET. In testing this 
database I simply substituted the database name in my ASP .NET program 
and was unable to connect to it. I'm getting an 
error "System.Data.SqlClient.SqlException: Cannot open database requested 
in login 'CDCatalog'. Login fails. Login failed for user 'WINXP\ASPNET' 
at System.Data.SqlClient.SqlConnection.Open() at 
ASP.sql_connection_cdcatalog_aspx.Page_Load().

I checked the security properties of the actual database files themselves 
(.mdf and .ldf). My new database did not have an entry for my logon so I 
added my XP logon and also ASPNET's (aspnet_wp) and gave them full 
rights. Any idea why this might be happening?
Code follows:

<%@ import Namespace="System.data" %>
<%@ import Namespace="System.data.SqlClient" %>
<script language="vb" runat="server">
Sub Page_Load()
'Set up our connection string and display on the page
Dim strConnection As String = "Integrated Security=SSPI;"
strConnection += "database=CDCatalog;server=WINXP\NETSDK;"
strConnection += "Connect Timeout=30"
data_src.text = strConnection

Dim objConnection as New SqlConnection(strConnection)

'Now we attempt to open the connection
try
objConnection.Open()
con_open.text="Connection opened successfully.<br />"
objConnection.Close()
con_close.text="Connection closed.<br />"
catch e as Exception
con_open.text="Connection failed to open.<br />"
con_close.text=e.ToString()
end try
End Sub
</script>

<html>
<body>
<h4>Testing the data connection
<asp:label id="data_src" runat="server"/></h4>
<asp:label id="con_open" runat="server"/><br />
<asp:label id="con_close" runat="server"/><br />
</body>
</html>
Message #2 by "Ashish M.bhonkiya" <Ashishm@p...> on Tue, 4 Feb 2003 17:40:18 +0530
hi roger,
you need to to give the permission to user ASPNET for that database.

you can do it by enterprise manager go to users for that database and add
the user and give him the following role of db_owner.

thats how i have solved. 
hope that helps you

regards
Ashish Bhonkiya.


-----Original Message-----
From: Roger Finks [mailto:rfinks01@e...]
Sent: Tuesday, February 04, 2003 5:41 PM
To: aspx_beginners
Subject: [aspx_beginners] Need Help Connecting to a SQL Database


I've used the sql_connect.aspx program from Chapter 12 of Beginning 
ASP.NET 1.0 to connect to an MSDE SQL database "northwind" that was 
created by .NET Quickstarts, Tutorials and Samples. I was able to connect 
okay. 

I then created a new database using Visual Studio .NET. In testing this 
database I simply substituted the database name in my ASP .NET program 
and was unable to connect to it. I'm getting an 
error "System.Data.SqlClient.SqlException: Cannot open database requested 
in login 'CDCatalog'. Login fails. Login failed for user 'WINXP\ASPNET' 
at System.Data.SqlClient.SqlConnection.Open() at 
ASP.sql_connection_cdcatalog_aspx.Page_Load().

I checked the security properties of the actual database files themselves 
(.mdf and .ldf). My new database did not have an entry for my logon so I 
added my XP logon and also ASPNET's (aspnet_wp) and gave them full 
rights. Any idea why this might be happening?
Code follows:

<%@ import Namespace="System.data" %>
<%@ import Namespace="System.data.SqlClient" %>
<script language="vb" runat="server">
Sub Page_Load()
'Set up our connection string and display on the page
Dim strConnection As String = "Integrated Security=SSPI;"
strConnection += "database=CDCatalog;server=WINXP\NETSDK;"
strConnection += "Connect Timeout=30"
data_src.text = strConnection

Dim objConnection as New SqlConnection(strConnection)

'Now we attempt to open the connection
try
objConnection.Open()
con_open.text="Connection opened successfully.<br />"
objConnection.Close()
con_close.text="Connection closed.<br />"
catch e as Exception
con_open.text="Connection failed to open.<br />"
con_close.text=e.ToString()
end try
End Sub
</script>

<html>
<body>
<h4>Testing the data connection
<asp:label id="data_src" runat="server"/></h4>
<asp:label id="con_open" runat="server"/><br />
<asp:label id="con_close" runat="server"/><br />
</body>
</html>

Message #3 by "Roger Finks" <rfinks01@e...> on Tue, 4 Feb 2003 19:30:06
> hi roger,
you need to to give the permission to user ASPNET for that database.

you can do it by enterprise manager go to users for that database and add
the user and give him the following role of db_owner.

thats how i have solved. 
hope that helps you

regards
Ashish Bhonkiya.


-----Original Message-----
From: Roger Finks [mailto:rfinks01@e...]
Sent: Tuesday, February 04, 2003 5:41 PM
To: aspx_beginners
Subject: [aspx_beginners] Need Help Connecting to a SQL Database


I've used the sql_connect.aspx program from Chapter 12 of Beginning 
ASP.NET 1.0 to connect to an MSDE SQL database "northwind" that was 
created by .NET Quickstarts, Tutorials and Samples. I was able to connect 
okay. 

I then created a new database using Visual Studio .NET. In testing this 
database I simply substituted the database name in my ASP .NET program 
and was unable to connect to it. I'm getting an 
error "System.Data.SqlClient.SqlException: Cannot open database requested 
in login 'CDCatalog'. Login fails. Login failed for user 'WINXP\ASPNET' 
at System.Data.SqlClient.SqlConnection.Open() at 
ASP.sql_connection_cdcatalog_aspx.Page_Load().

I checked the security properties of the actual database files themselves 
(.mdf and .ldf). My new database did not have an entry for my logon so I 
added my XP logon and also ASPNET's (aspnet_wp) and gave them full 
rights. Any idea why this might be happening?
Code follows:

<%@ import Namespace="System.data" %>
<%@ import Namespace="System.data.SqlClient" %>
<script language="vb" runat="server">
Sub Page_Load()
'Set up our connection string and display on the page
Dim strConnection As String = "Integrated Security=SSPI;"
strConnection += "database=CDCatalog;server=WINXP\NETSDK;"
strConnection += "Connect Timeout=30"
data_src.text = strConnection

Dim objConnection as New SqlConnection(strConnection)

'Now we attempt to open the connection
try
objConnection.Open()
con_open.text="Connection opened successfully.<br />"
objConnection.Close()
con_close.text="Connection closed.<br />"
catch e as Exception
con_open.text="Connection failed to open.<br />"
con_close.text=e.ToString()
end try
End Sub
</script>

<html>
<body>
<h4>Testing the data connection
<asp:label id="data_src" runat="server"/></h4>
<asp:label id="con_open" runat="server"/><br />
<asp:label id="con_close" runat="server"/><br />
</body>
</html>

Message #4 by "Roger Finks" <rfinks01@e...> on Wed, 5 Feb 2003 11:34:23
Is there anyway to do this without enterprise manager. I don't have 
enterprise manager because I'm using MDSE and not full blown SQL Server.

> hi roger,
you need to to give the permission to user ASPNET for that database.

you can do it by enterprise manager go to users for that database and add
the user and give him the following role of db_owner.

thats how i have solved. 
hope that helps you

regards
Ashish Bhonkiya.


-----Original Message-----
From: Roger Finks [mailto:rfinks01@e...]
Sent: Tuesday, February 04, 2003 5:41 PM
To: aspx_beginners
Subject: [aspx_beginners] Need Help Connecting to a SQL Database


I've used the sql_connect.aspx program from Chapter 12 of Beginning 
ASP.NET 1.0 to connect to an MSDE SQL database "northwind" that was 
created by .NET Quickstarts, Tutorials and Samples. I was able to connect 
okay. 

I then created a new database using Visual Studio .NET. In testing this 
database I simply substituted the database name in my ASP .NET program 
and was unable to connect to it. I'm getting an 
error "System.Data.SqlClient.SqlException: Cannot open database requested 
in login 'CDCatalog'. Login fails. Login failed for user 'WINXP\ASPNET' 
at System.Data.SqlClient.SqlConnection.Open() at 
ASP.sql_connection_cdcatalog_aspx.Page_Load().

I checked the security properties of the actual database files themselves 
(.mdf and .ldf). My new database did not have an entry for my logon so I 
added my XP logon and also ASPNET's (aspnet_wp) and gave them full 
rights. Any idea why this might be happening?
Code follows:

<%@ import Namespace="System.data" %>
<%@ import Namespace="System.data.SqlClient" %>
<script language="vb" runat="server">
Sub Page_Load()
'Set up our connection string and display on the page
Dim strConnection As String = "Integrated Security=SSPI;"
strConnection += "database=CDCatalog;server=WINXP\NETSDK;"
strConnection += "Connect Timeout=30"
data_src.text = strConnection

Dim objConnection as New SqlConnection(strConnection)

'Now we attempt to open the connection
try
objConnection.Open()
con_open.text="Connection opened successfully.<br />"
objConnection.Close()
con_close.text="Connection closed.<br />"
catch e as Exception
con_open.text="Connection failed to open.<br />"
con_close.text=e.ToString()
end try
End Sub
</script>

<html>
<body>
<h4>Testing the data connection
<asp:label id="data_src" runat="server"/></h4>
<asp:label id="con_open" runat="server"/><br />
<asp:label id="con_close" runat="server"/><br />
</body>
</html>

  Return to Index