Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

connect to sql server form aspx

Status
Not open for further replies.

yahoo182

Programmer
Jul 5, 2005
70
CA
Hi there, in the following code, I am trying to connect to my sql server from C# aspx code. However, when I run it, i seem to get the following error.

In my sql server security/login setting, I have testuser to access the Northwind db and permit db role as public.

any sort of input is greately appriciated!
thanks :)


Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.
Source Error:
Line 11:
Line 12: DataSet ds = new DataSet();
Line 13: myCommand.Fill(ds, "Orders");
Line 14:
Line 15: MyDataGrid.DataSource=ds.Tables["Orders"].DefaultView;


Code:
<%@ Page Language="C#" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<html>
<script language="C#" runat="server">

protected void Page_Load(Object sender, EventArgs e) {
  SqlConnection myConnection = new SqlConnection("Database=Northwind;Server=localhost;In\
tegrated Security=SSPI; User ID=KKCOMPUTER\\testuser; Password=passwd");
  SqlDataAdapter myCommand = new SqlDataAdapter("select * from Orders", myConnection);

  DataSet ds = new DataSet();
  myCommand.Fill(ds, "Orders");

  MyDataGrid.DataSource=ds.Tables["Orders"].DefaultView;
  MyDataGrid.DataBind();
}

</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>
 
Try removing Integrated Security=SSPI; from your connection string. This is telling the connection to use integrated security and might be overriding your username and pw parameters.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top