Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the 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 June 27th, 2004, 11:16 AM
Authorized User
 
Join Date: Jun 2004
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Default Making database connections using the OleDbConnect

Has anyone had any problems with making a connection to the Northwind database using the OleDbConnection
described in chapter 9 in the Executing Commands Directory example?
I find that my browser shows a compilation error at line 8 which is where we call the open method of the OleDbConnection?
I.e. dbConnection.open on which the compiler is looking for a new declaration suggesting that the link has not been made.

ERROR REPORT
Server Error in '/BookASP_NET' Application.

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request.
Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30188: Declaration expected.

Source Error:

Line 6: "Data Source=C:\BegASPNET11\data\Northwind.mdb"
Line 7: Dim dbConnection As New OleDbConnection(connectionString)
Line 8: dbConnection.Open()
Line 9: Line 10: Dim commandString As String = "INSERT INTO Employees(FirstName, LastName) " & _

Source File: c:\inetpub\wwwroot\BookASP_NET\CH9\CommandExecute. aspx Line: 8

Source Code
<%@ Import Namespace="System.Data.OleDB" %>
<%@ Page Language="vb" %>

<script runat="server">
Dim connectionString = "Provider=Microsoft.jet.OLEDB.4.0; " & _
         "Data Source=C:\BegASPNET11\data\Northwind.mdb"
Dim dbConnection As New OleDbConnection(connectionString)
dbConnection.Open() <-----Error line: compiler requires this declared

Dim commandString As String = "INSERT INTO Employees(FirstName, LastName) " & _
   "Values(@FirstName, @LastName)"

Dim dbCommand As New OleDbCommand(commandString, dbConnection)
Dim firstNameParam As New OleDbParameter("@FirstName", OleDBType.VarChar, 10)
firstNameParam.Value = txtFirstName.Text
dbCommand.Parameters.Add(firstNameParam)
Dim lastNameParam As New OleDbParameter("@LastName", OleDbType.VarChar, 20)
lastNameParam.Value = txtLastName.Text
dbCommand.Parameters.Add(lastNameParam)

dbCommand.ExecuteNonQuery()

dbConnection.Close()
</script>
Note: this code is what I have taken from the book, continuation characters are used where the line is too long for a single line entry - other broken lines are due to the word wrapping of this topic forms table element. I have not listed the HTML bit at the bottom.

 
Old June 27th, 2004, 04:31 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hello,

Have you declared dbConnection previously, and this may be a double-declaration?

Brian
 
Old June 28th, 2004, 10:27 AM
Authorized User
 
Join Date: Jun 2004
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Brian,
Thanks for your reply as below.
(Have you declared dbConnection previously, and this may be a double-declaration?)
No dbConnection is declared in line 7, the compiler is calling for dbConnection.Open to be declared as a new variable.
The code that I have written is listed in my original topic, I should add however that I am not using Webmatrix but Visual Studio, I am assured however that the code is similar (or the same even) for both compilers, I had experienced a problem with the previous exercise which Imar Spaanjaars talked me through, this turned out to be a security issue, which I will report on as a seperate topic soon.
Regards,

Edward.


 
Old June 28th, 2004, 11:16 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Edward,

Can you post more code for the page maybe all of it)? Although the text editor may show you a line break, it still is only a "soft line break". That means that you can type a long line and paste it here. In the editor it will be wrapped, but in the post it will be like the original line.

If you're worried about us not understanding the code, you could add the line continuation characters yourself before you post the code here.

You say you're using Visual Studio .NET, yet the error seems to indicate in-line code. What code model are you using? Do you use Code Behind? If so, did you compile the application before you requested the page in the browser?

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: The Mercy Seat (video mix) by Nick Cave and the Bad Seeds (Track 11 from the album: Tender Prey) What's This?
 
Old June 28th, 2004, 11:30 AM
Registered User
 
Join Date: Jun 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

when i write this script received the following error

<%
set myconn = server.createobject("adodb.connection")
connection = Driver = {Mysql}; &
         Server=localhost; &
            Database = employee; &
         UID=root; &
         PWD=root; &
myconn.open(connection)
%>


Error Type:
Microsoft VBScript compilation (0x800A0408)
Invalid character
/hris/hrisa.asp, line 3, column 22

<%



 
Old June 28th, 2004, 11:41 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,101
Thanks: 0
Thanked 2 Times in 2 Posts
Default

TeeJay- when you have a problem with something you should post in a new thread.. not use someone elses. Please repost your question in a new thread.


Hal Levy
Web Developer, PDI Inc.

NOT a Wiley/Wrox Employee
 
Old June 28th, 2004, 01:02 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi teejaymt,

And if you do repost your question, can you post it in another forum? This forum is for ASP.NET while your questions seems related to "classic" ASP. Posting in the right forum usually gives you a quicker and better answer.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Medicine (Matrix Remix) by Ed Rush & Optical (Track 9 from the album: Wormhole #2) What's This?
 
Old June 29th, 2004, 10:39 AM
Authorized User
 
Join Date: Jun 2004
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar, I cannot believe it!! I have it working.
The problem of displaying the code with word wrapping of the text has made me look at the code downloaded from the site so that I could say "this is what I have used".
I rebuilt the page entering the form tools from the Tool box and editing in their properties in the Design view double clicked the "Run" button which opened CommandExecute2.aspx.vb (which I could not recall previously happening) I copied the code
(Sub btnRun_Click(ByVal sender As System.Object, ByVal e As System.EventArgs))into the .aspx File then the code between Sub and End Sub from the down loaded version compiled the result and it worked!
I have checked out my original WebForm page and find that it lacked the event handler "Sub" and "End" code lines, having added these the original copy compiled and run. I guess that WebMatrix writes the event handler code to the .aspx file where a Visual Studio writes it to the .aspx.vb file?
I must watch for this in future - thanks to all who replied to my topic and an especial thanks to Imar who has been very patient.

 
Old June 29th, 2004, 10:48 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Great news! Congratulations.

Yes, Visual Studio uses the Code Behind model, and the Web Matrix uses in-line code. This is a big difference you need to be aware of.
In-line code results in "stand alone pages", that you can request directly. Code Behind pages are compiled at design time to one big assembly file. This assembly file is then used at run-time to give the pages their behavior.

Glad it is working now.

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: The Bends by Radiohead (Track 2 from the album: The Bends) What's This?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple Database Connections rit01 ASP.NET 1.x and 2.0 Application Design 6 September 20th, 2006 12:42 PM
Database - connections gkn Oracle 1 December 20th, 2005 08:25 AM
Database - connections gkn Oracle 0 December 20th, 2005 07:27 AM
MS Access database connections proud900 BOOK: ASP.NET Website Programming Problem-Design-Solution 1 June 22nd, 2005 08:21 PM
multiple database connections markhardiman Classic ASP Databases 7 September 9th, 2004 05:15 AM





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