Subject: Connecting to a SQL data source
Posted By: aptbid2002 Post Date: 10/29/2003 4:41:15 PM
Okay chapter 3 first example for some reason will not let me connect to northwind. Error states I have a login error so naturally I said "ah" and went to the Northwind.mdf file and gave ASPNET permissions to use the file, however, I still receive the error. Any help would suffice.

"Is the glass half full, half empty, or twice as large as it needs to be?"
Reply By: melvik Reply Date: 10/29/2003 11:50:00 PM
can u post ur ConnectionString?! that should be something like this.
data source=YOUR_SERVER;initial catalog=northwind;password=YOURPASS;persist security info=True;user id=USER_NAME;packet size=4096

Always,
Hovik Melkomian.
Reply By: andresaw Reply Date: 11/26/2003 12:02:37 PM
Chapter 03 first and second example, although i typed the code exactly the same from book, in both cases, i can only see the heading with <h3>. the rest of the table can't be seen in both examples. Then, I replace the files with the one from download code, the same problem. Is it my connection error or what? I put the code as follows.

First Example

<%@ Import namespace="System.Data" %>
<%@ Import namespace="System.Data.SqlClient" %>

<html>
  <head>
    <title>Beginning ASP.NET Databases Using C#: Chapter 3</title>
  </head>

  <body>
    <h4>First Example: Listing data from the Employees table</h4>
    <asp:DataGrid id="dgNameList"
                  runat="server"
                  GridLines="None"
                  BackColor="LightBlue"
                  CellPadding="5"
                  CellSpacing="5"
                  BorderWidth="2"
                  BorderColor="Black"
                  ToolTip="Includes only those employees who are at HQ" />
  </body>
</html>

<script language="c#" runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
  String strConnection = "server=(local)\\NetSDK; database=Northwind; integrated security=true;";
  SqlConnection objConnection = new SqlConnection(strConnection);

  String strSQL = "SELECT FirstName, LastName, Country " + "FROM Employees";
  SqlCommand objCommand = new SqlCommand(strSQL, objConnection);

  objConnection.Open();
  dgNameList.DataSource = objCommand.ExecuteReader();
  dgNameList.DataBind();
  objConnection.Close();
}
</script>
-----------------------------------------------------------------------------------
Second Example
..............

<%@ Import namespace="System.Data" %>
<%@ Import namespace="System.Data.OleDb" %>

<html>
  <head>
    <title>Connecting to an Access Database</title>
  </head>

  <body>
    <H3>Connecting to an Access Database</H3>
    <asp:DataGrid id="dgSuppliers" runat="server" />
  </body>
</html>

<script language="c#" runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
  String strConnection = "Provider=Microsoft.Jet.OleDb.4.0; data source=C:\\7418BegASPNETdbCS\\datastores\\Northwind.mdb;";
  OleDbConnection objConnection = new OleDbConnection(strConnection);

  String strSQL = "SELECT SupplierID, CompanyName FROM Suppliers";
  OleDbCommand objCommand = new OleDbCommand(strSQL, objConnection);

  objConnection.Open();
  dgSuppliers.DataSource = objCommand.ExecuteReader();
  dgSuppliers.DataBind();
  objConnection.Close();
}
</script>


Go to topic 6910

Return to index page 998
Return to index page 997
Return to index page 996
Return to index page 995
Return to index page 994
Return to index page 993
Return to index page 992
Return to index page 991
Return to index page 990
Return to index page 989