|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
ASP.NET & SQL Server (Getting Started)
Good day everyone.
I'm new to SQL/ASP.NET and the Visual Studio environment. I'm trying to get a simple example to work from a book that I'm learning from: "Moving to ASP.NET: Web Development with VB.NET" I have SQL Server 7.0 installed on my Windows 2000 desktop and I'm working in Visual Studio.Net. I have windows authentication security mode on SQL Server. I'm performing a simple page that reads data from the database and I'm getting this error: ---error--- Login failed for user 'sa'. 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.Data.OleDb.OleDbException: Login failed for user 'sa'. ---error--- I've been told that I need to have SQL Server authenticate the "ASP.NET _process", but I'm not sure how to do this, nor how to verify that this authentication is working properly. Any help is greatly appreciated! |
|
#2
|
||||
|
||||
|
1) For SQL Server 7.0 You need to use the SqlConnection object...not OleDb.
Create a reference to System.Data.SqlClient The best way to do it would be to create a new user in sql server. Then give that user rights to whatever database you are wanting to work with. Code:
Dim objConn As SqlConnection
Dim objCmd As SqlCommand
Dim reader As Reader
'Set the Connection object
objConn = New SqlConnection("Driver={SQL Server};User ID=username;PWD=password;Database=dbName")
'Set the Command object
objCmd=New SqlCommand("SELECT * FROM TableName", objConn)
Try
objConn.Open()
reader = objCmd.ExecuteReader()
While(reader.Read())
Response.write(Convert.ToString(reader("fieldName")))
End While
reader.Close()
objConn.Close()
Catch ex As Exception
Response.write("Error: " & ex.Message)
End Try
|
|
#3
|
|||
|
|||
|
Memnoch,
thanks for replying. Few things. 1. Actually, I'm not sure that I'm running 7.0. I'm not even sure how I can determine what version of SQL Server I'm running. When I'm in enterprise manager, the "about SQL Server enterprise manager" box says version 8.00.194. So can I use the OleDbConnection? 2. I have attempted to give a user rights to the database. This is what I did: - Local SQL Server > Securty > Logins: new login Test - Test is Standard with SQL Server Authentication - Test was given access to one database, called "HiFlyers" ---error--in--more--detail---- Server Error in '/HiFlyers' Application. -------------------------------------------------------------------------------- Login failed for user 'Test'. 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.Data.OleDb.OleDbException: Login failed for user 'Test'. Source Error: Line 23: 'Put user code to initialize the page here Line 24: Dim CN As New OleDbConnection("Provider=SQLOLEDB.1;Data Source=(local);Initial Catalog=HiFlyers;User ID=Test;") Line 25: CN.Open() Line 26: Dim CM As New OleDbCommand( _ Line 27: "SELECT AircraftID, Registration, Manuf, Model FROM Aircraft", CN) Source File: c:\inetpub\wwwroot\HiFlyers\AircraftList.aspx.vb Line: 25 Stack Trace: [OleDbException (0x80040e4d): Login failed for user 'Test'.] System.Data.OleDb.OleDbConnection.ProcessResults(I nt32 hr) +20 System.Data.OleDb.OleDbConnection.InitializeProvid er() +57 System.Data.OleDb.OleDbConnection.Open() +203 HiFlyers.AircraftList.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\HiFlyers\AircraftList.aspx.vb:2 5 System.Web.UI.Control.OnLoad(EventArgs e) +67 System.Web.UI.Control.LoadRecursive() +35 System.Web.UI.Page.ProcessRequestMain() +731 -------------------------------------------------------------------------------- Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573 ---error--in--more--detail---- Again, I'm very grateful for any help! |
|
#4
|
||||
|
||||
|
To check the version, open query analyzer and type
Code:
SELECT @@Version Version 8.0xxx seems like SQL Server 2000 For SQL Server 7.0 and 2000 use System.Data.SqlClient For SQL Server 6.5 or earlier use System.Data.OleDb 2) Did you give the Test login a password? Steps to add a new user 1) Security>New Login On General Tab 2) Type the username 3) Select SQL Server Authentication and type in the password 4) From the database drop down select the default database for this user. On Database Access Tab Check the "Permit" box next to the default database for this user. Then check the db_owner box for database roles below that. Then confirm the password for the user. |
![]() |
| Viewing: ASP Free Forums > Database > Microsoft SQL Server > ASP.NET & SQL Server (Getting Started) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|