?
Solved

ASP.NET Connection Problem (Newbie Question)

Posted on 2005-04-09
18
Medium Priority
?
221 Views
Last Modified: 2010-04-07
I'm trying to follow a tutorial from the WROX book "Beginning ASP.NET Databases using VB.NET."

The example is supposed to show how to make a connection to a database.  The .aspx page is as follows:

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

<html>
  <head>
    <title>Beginning ASP.NET Databases Chapter 3</title>
  </head>

  <body>
    <h4>First Example: Listing data from the Employees table, bitch</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="VB" runat="server">
Sub Page_Load(Source As Object, E As EventArgs)
  Dim strConnection As String = "server={local)\BasicDB; database=Northwind; " & _
                                "integrated security=true"
  Dim objConnection As New SqlConnection(strConnection)

  Dim strSQL As String = "SELECT FirstName, LastName, Country " & _
                         "FROM Employees;"
  Dim objCommand As New SqlCommand(strSQL, objConnection)

  objConnection.Open()

  Response.Write("ServerVersion: " & objConnection.ServerVersion & _
                 vbCRLF & "Datasource: " & objConnection.DataSource & _
                 vbCRLF & "Database: " & objConnection.Database)

  dgNameList.DataSource = objCommand.ExecuteReader()
  dgNameList.DataBind()
  objConnection.Close()
End Sub
</script>
"

I obviously had to change the server path to the location of the database, so I did that.  I used the same path designation that I used to create the connection in the first place.

When I look at this page in a web browser, it shows the text at the top, but displays no table.  I've been changing around the server path to see if I can get it, but no luck.  No matter what I put, it doesn't work.  Is this the source of my problem?  Or is it probably something else?  The rest of the page is directly from the supplied files and the book has a good record of having good source files, so I'm fairly certain there's no real problem with it...

Thanks for any help...
0
Comment
Question by:brassmonkeyboy
  • 10
  • 8
18 Comments
 
LVL 12

Expert Comment

by:laotzi2000
ID: 13746150
First, the second <body> should be </body>

Second, the connection string is not right, it should be server=(local)\BasicDB;  Or just server=(local)
If you installed multiple sql server, you should use the first one, or the second one if there is only one sql server
instance installed on your computer.
0
 
LVL 12

Expert Comment

by:laotzi2000
ID: 13746159
Third, I don't think integrated security will work if you have not configured your aspnet account in your sql server database.
So you should change it to "uid=[your user name(normally sa)];password=[the password of the user id];"
0
 
LVL 12

Expert Comment

by:laotzi2000
ID: 13746167
For your information, the following code works for me, I only omit my sa password in the connection string:
<%@ Import namespace="System.Data" %>
<%@ Import namespace="System.Data.SqlClient" %>

<html>
  <head>
    <title>Beginning ASP.NET Databases Chapter 3</title>
  </head>

  <body>
    <h4>First Example: Listing data from the Employees table, bitch</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="VB" runat="server">
Sub Page_Load(Source As Object, E As EventArgs)
  Dim strConnection As String = "server=(local); database=Northwind; " & _
                                "uid=sa;password="
  Dim objConnection As New SqlConnection(strConnection)

  Dim strSQL As String = "SELECT FirstName, LastName, Country " & _
                         "FROM Employees;"
  Dim objCommand As New SqlCommand(strSQL, objConnection)

  objConnection.Open()

  Response.Write("ServerVersion: " & objConnection.ServerVersion & _
                 vbCRLF & "Datasource: " & objConnection.DataSource & _
                 vbCRLF & "Database: " & objConnection.Database)

  dgNameList.DataSource = objCommand.ExecuteReader()
  dgNameList.DataBind()
  objConnection.Close()
End Sub
</script>
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:brassmonkeyboy
ID: 13746208
I changed all those things and nothing changed...any other ideas...
0
 
LVL 12

Expert Comment

by:laotzi2000
ID: 13746223
and you should check your sql server to see if it is using mixed authentication
and put the correct sa password in the connection string
0
 

Author Comment

by:brassmonkeyboy
ID: 13746271
I put the correct password and still the same...only the text in the HTML section...no ASP anything...

How would I check the server to see if it's using mixed authentication?
0
 
LVL 12

Expert Comment

by:laotzi2000
ID: 13747461
in enterprise manager,
right click on your sql server instance, choose properties,
then in the security tab, you will see the authention method,
you should choose to use both windows and sql server
0
 

Author Comment

by:brassmonkeyboy
ID: 13748629
I'm using MSDE...so I don't have enterprise manager.

I would think that we're barking up the wrong tree on this simply because when I added the database using VB.NET's Server Explorer, I told it to log on using integrated security and it worked perfectly.  Am I just not understanding what's going on?
0
 

Author Comment

by:brassmonkeyboy
ID: 13748670
Here's something that may help figure this out...

When I go to a web browser on my computer I can't see the local web server by typing in "http://localhost,"  I have to type "http://localhost:82" to see it.

Could the reason behind this be the same reason I'm having the above problems?  If so, how would I fix it?
0
 
LVL 12

Expert Comment

by:laotzi2000
ID: 13748689
the thing is when you added it in server explorer, you're using the logged on account to authenticate, i guess it might be administrator.
But when you connect to the database in your code, you're using account ASPNET to authenticate.
There is a big difference here.
0
 
LVL 12

Expert Comment

by:laotzi2000
ID: 13748699
And you web server is listening on port 82 instead of the default 80,
don't think it should be the reason here.
0
 

Author Comment

by:brassmonkeyboy
ID: 13748716
AH.  I get it.  But the sa and password don't seem to help any still...
0
 
LVL 12

Expert Comment

by:laotzi2000
ID: 13748734
I doubt if your page_load function is called or not.
Test by add
Response.Write("Hello")
at the beginning of Page_Load
0
 

Author Comment

by:brassmonkeyboy
ID: 13749575
You're right...it's not loading.  Why would that be?
0
 
LVL 12

Accepted Solution

by:
laotzi2000 earned 2000 total points
ID: 13749739
try run this in Visual Studio .net command prompt:
aspnet_regiis -i
0
 

Author Comment

by:brassmonkeyboy
ID: 13750087
I can't seem to locate the prompt...where is it?  Also, what will this tell me?
0
 
LVL 12

Expert Comment

by:laotzi2000
ID: 13750112
It's a program,
look for it in the visual studio .net tools
0
 

Author Comment

by:brassmonkeyboy
ID: 13750115
Never mind that, I found it.  I typed that and it installed ASP.Net.  AND another page shows up now...an error.  But you solved my problem so I'll start a new thread about this next problem:-)  Thanks man!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question