Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 1.1
This is the forum to discuss the Wrox book Beginning ASP.NET 1.1 with Visual C#.NET 2003 by Chris Ullman, John Kauffman, Chris Hart, Dave Sussman, Daniel Maharry; ISBN: 9780764557088
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 29th, 2005, 06:59 AM
Registered User
 
Join Date: Jan 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default error conecting to the DB

Hello,
My problem is that I have a C# code conecting to SQLSERVER working perfectly, but when I try to conect it with an ASPX page, it doesn,t connect.

the code for the ASPX page is this:

<%@ Page Language="C#" Debug="true" Src="adooverview1.cs"%>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="HowTo.Samples.ADONET" %>

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

protected void Page_Load(Object Src, EventArgs E)
{
  StringWriter writer = new StringWriter();
  Console.SetOut(writer);
  adooverview1 myadooverview1 = new adooverview1();
  myadooverview1.Run();
  output.InnerHtml = writer.ToString();
}

</script>


<html>
<body style="background-color:f6e4c6">
  <tr><td><h4><xmp id="output" runat="server"/></h4></td></tr>
</body>
</html>

Thanks

ART
 
Old January 31st, 2005, 10:39 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

What does this do: adooverview1?

Brian
 
Old February 13th, 2005, 10:40 AM
Registered User
 
Join Date: Jan 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is the C# code of adooverview1.cs:
It connects to the database but when I try it wit ASPX it doesn't work.

namespace ejemplo
{

using System;
using System.Data.SqlClient;

public class adooverview1
{
  public static void Main()
  {
    adooverview1 myadooverview1 = new adooverview1();
    myadooverview1.Run();
  }

  public void Run()
  {

    SqlConnection mySqlConnection = new SqlConnection("server=(local)\\NetSDK;Trusted_Conn ection=yes;database=hotel");

    try
    {
      mySqlConnection.Open();
      Console.WriteLine("Opened Connection to {0}", mySqlConnection.ConnectionString);

      // Close the connection explicitly
      mySqlConnection.Close();
      Console.WriteLine("Closed Connection. It is important to close connections explicitly.");
    }
    catch
    {
      Console.WriteLine("Couldn't Open Connection to {0}", mySqlConnection.ConnectionString);
    }
  }
}

}


ART
 
Old February 13th, 2005, 10:44 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You're writing to the Console, which is not available in ASP.NET

Remove the lines that use Console. and then debug your application Move line by line through the code to see where it breaks....

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: The new cobweb summer by Lambchop (From the album: Is a woman) What's This?





Similar Threads
Thread Thread Starter Forum Replies Last Post
problem conecting to MySql - please help daemyenn MySQL 2 October 29th, 2006 09:26 PM
restore DB error RinoDM SQL Server 2000 6 October 6th, 2006 04:18 PM
Form to db Error on " ' " merchafil Classic ASP Databases 1 December 5th, 2005 07:34 AM
Insert into db error keyvanjan Classic ASP Databases 1 December 5th, 2005 07:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.