Login failed for user 'sa'. Reason: Not associated with a trusted SQL Server
connection.
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.SqlClient.SqlException: Login failed for user
'sa'. Reason: Not associated with a trusted SQL Server connection.
Source Error:
Line 15:
Line 16: objConexion = New
SqlConnection("server=(local);uid=sa;pwd=;database =northwind")
Line 17: objConexion.Open()
Line 18:
Line 19: objComando = New SqlCommand("Select * From categories",
objConexion)
Cannot open database requested in login 'pubs'. Login fails. Login failed
for user 'WILLIAM2\ASPNET'.
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.SqlClient.SqlException: Cannot open database
requested in login 'pubs'. Login fails. Login failed for user
'WILLIAM2\ASPNET'.
Source Error:
Line 16: ' Create and fill a DataSet.
Line 17: Dim ds As DataSet = new DataSet()
Line 18: myCommand.Fill(ds)
Line 19: ' Bind MyDataGrid to the DataSet. MyDataGrid is the
Line 20: ' ID for the DataGrid control in the HTML section
"Franco Figún" <fr********@fibertel.com.ar> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Try this code, and tell me what you see:
<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<HTML>
<HEAD>
<TITLE>ADO.NET</TITLE>
</HEAD>
<BODY>
<%
Dim objConexion As SqlConnection
Dim objComando As SqlCommand
Dim objDataReader As SqlDataReader
Dim intContador As Integer
objConexion = New
SqlConnection("server=PC;uid=sa;pwd=;database=nort hwind") objConexion.Open()
objComando = New SqlCommand("Select * From categories", objConexion)
objDataReader = objComando.ExecuteReader()
%>
<%
intContador = 1
Response.Write("<TABLE
BORDER=1><TR><TD>NRO</TD><TD>ID</TD><TD>NOMBRE</TD></TR>")
While objDataReader.Read
Response.Write("<TR><TD>" & intContador & ".</TD><TD>" &
objDataReader.Item("categoryID") & "</TD><TD>" &
objDataReader.Item("categoryname") & "</TD></TR>")
intContador = intContador + 1
End While
Response.Write("</TABLE>")
objDataReader.Close()
objConexion.Close()
%>
</BODY>
</HTML>
------------------------------------------------------------------
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<script language="VB" runat="server">
Sub Page_Load(Src As Object, e As EventArgs)
Dim myConnection As SqlConnection
Dim myCommand As SqlDataAdapter
' Create a connection to the "pubs" SQL database located on the
' local computer.
myConnection = New SqlConnection("server=localhost;" _
& "database=pubs;Trusted_Connection=Yes")
' Connect to the SQL database using a SQL SELECT query to get all
' the data from the "Authors" table.
myCommand = new SqlDataAdapter("SELECT * FROM Authors", _
myConnection)
' Create and fill a DataSet.
Dim ds As DataSet = new DataSet()
myCommand.Fill(ds)
' Bind MyDataGrid to the DataSet. MyDataGrid is the
' ID for the DataGrid control in the HTML section.
MyDataGrid.DataSource = ds
MyDataGrid.DataBind()
End Sub
</script>
<body>
<h3><font face="Verdana">
Simple Select to a DataGrid Control.
</font></h3>
<ASP:DataGrid id="MyDataGrid" runat="server"
Width="700"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
EnableViewState="false"
/>
</body>
</html>