Function name not declared?

Z

Zak

I've been working on converting one of the major sites in my company to ASP.
net. I started with the migration assistant from Microsoft, which may or may
not have been a good idea. It worked OK on the last conversion though.

In trying to develop good coding practices, I'm using Option Strict. When I
made my last conversion, I wrote a relatively simple function where you
passed in an SQL string, and it returned an SqlDataReader. Worked great on
that site, but on this one I get the following error:

Compiler Error Message: BC30451: Name 'OpenRDR' is not declared.

Source Error:

Line 85: Dim sql as String = "SELECT * FROM All_Schools WHERE
TeamName='FRONT'"
Line 86: rdr = OpenRDR(sql)


Here is the dbsupport file as it currently is.

<script language="VB" runat="Server">
function OpenRDR(ByRef sql As String) As SqlDataReader
Dim Conn As SqlConnection = new SqlConnection(ConfigurationSettings.
AppSettings("ConnectionString"))
Dim dbComm As SqlCommand = new SqlCommand(sql,conn)
Dim rs As SqlDataReader

Conn.Open()
rs = dbComm.ExecuteReader(CommandBehavior.CloseConnection)
return rs
end function
</script>

Have I missed something in all my reading? I've only been at .NET for about
a week and a half, but I never saw anything like this in ASP. Any ideas are
welcome.
 
Z

Zak

Yes sir, just a basic SSI.

<!--include file="ssi/dbsupport.aspx" -->

Where the function above is the only thing in dbsupport.aspx

S. Justin Gengo said:
Zak,

Have your referenced the support file?
I've been working on converting one of the major sites in my company to
ASP.
[quoted text clipped - 37 lines]
are
welcome.
 
J

Josh Kerr

I didn't know that you could use includes in aspx pages.

Move the function to a class and reference that class from the page.
The code will execute faster because it will be compiled.

Zak said:
Yes sir, just a basic SSI.

<!--include file="ssi/dbsupport.aspx" -->

Where the function above is the only thing in dbsupport.aspx

S. Justin Gengo said:
Zak,

Have your referenced the support file?
I've been working on converting one of the major sites in my company to
ASP.
[quoted text clipped - 37 lines]
are
welcome.
 
S

S. Justin Gengo

Zak,

Are there other functions in that support file that you can call? Or do you
not have access to any of them from that page? If you don't have access to
any of them I'd check that you have the full path to the support file
written out properly. For example if there is a user control being dropped
onto a page it is easy to forget that the control may need a different path
to a file than the page itself uses...

That's my best guess so far.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
Zak said:
Yes sir, just a basic SSI.

<!--include file="ssi/dbsupport.aspx" -->

Where the function above is the only thing in dbsupport.aspx

S. Justin Gengo said:
Zak,

Have your referenced the support file?
I've been working on converting one of the major sites in my company to
ASP.
[quoted text clipped - 37 lines]
are
welcome.
 
Z

Zak

There were no other functions in dbsupport, but I added another, extremely
simple one in order to test, and could not access it. Next, I tried losing
the SSI and converting it into a user control. Well, it appears to have been
properly converted (there are no errors relating to it), but I continue to
have the same problem accessing my function. The included file is simply one
directory down from the index.aspx file, in ssi/dbsupport.ascx (now, was aspx)
.. Still no joy. Thanks so far.

I don't know enough about VB to be comfortable trying to make this a class.
Is there any other options?

S. Justin Gengo said:
Zak,

Are there other functions in that support file that you can call? Or do you
not have access to any of them from that page? If you don't have access to
any of them I'd check that you have the full path to the support file
written out properly. For example if there is a user control being dropped
onto a page it is easy to forget that the control may need a different path
to a file than the page itself uses...

That's my best guess so far.
Yes sir, just a basic SSI.
[quoted text clipped - 11 lines]
 
M

Marina

You should not be using include files in ASP.NET.

This looks like something that should be in a class library, or something
that can be called via inheritance.
 
J

Juan T. Llibre

re:
I didn't know that you could use includes in aspx pages.

You *can* use includes, but any code in them won't execute.
They're OK for HTML, but I prefer to use web user controls for that.

re:
Move the function to a class and reference that class from the page.

Good advice...




Josh Kerr said:
I didn't know that you could use includes in aspx pages.
Move the function to a class and reference that class from the page. The code will
execute faster because it will be compiled.
Zak said:
Yes sir, just a basic SSI.

<!--include file="ssi/dbsupport.aspx" -->

Where the function above is the only thing in dbsupport.aspx

S. Justin Gengo said:
Zak,

Have your referenced the support file?

I've been working on converting one of the major sites in my company to
ASP.
[quoted text clipped - 37 lines]
are
welcome.
 
Z

Zak

OK, I'm trying (big emphasis on trying) to make a class. Here is my vb code:

Imports System.Data
Imports System.Data.SqlClient

Namespace DBSupport
Public Class dataRdr
Public Function OpenRDR(ByRef sql As String) As SqlDataReader
Dim Conn As SqlConnection = New SqlConnection
("Server=ServerStuff;Database=ffn;User
ID=pub;Password=sa;Trusted_Connection=False")
Dim dbComm As SqlCommand = New SqlCommand(sql, Conn)
Dim rs As SqlDataReader

Conn.Open()
rs = dbComm.ExecuteReader(CommandBehavior.CloseConnection)
Return rs
End Function
End Class
End Namespace

Compliled that, put it in the /bin directory, then Imported the namespace on
my page:
<%@ Import Namespace="DBSupport" %>

Here's where it might be shaky:
Dim testthing As new DBSupport.dataRdr
Dim sql as String = "SELECT * FROM All_Schools WHERE TeamName='FRONT'"
rs = testthing.OpenRDR(sql)

You should not be using include files in ASP.NET.

This looks like something that should be in a class library, or something
that can be called via inheritance.
I've been working on converting one of the major sites in my company to
ASP.
[quoted text clipped - 37 lines]
are
welcome.
 
Z

Zak

Oh, and my current error is:

Compiler Error Message: BC30002: Type 'DBSupport.dataRdr' is not defined.

Source Error:

Line 82: <div style='position:absolute;top:420;left:192;height:10;width:
480;height:257;text-align:left' class='whitebg'>
Line 83: <%
Line 84: Dim testthing As new DBSupport.dataRdr
Line 85: Dim sql as String = "SELECT * FROM All_Schools WHERE
TeamName='FRONT'"

OK, I'm trying (big emphasis on trying) to make a class. Here is my vb code:

Imports System.Data
Imports System.Data.SqlClient

Namespace DBSupport
Public Class dataRdr
Public Function OpenRDR(ByRef sql As String) As SqlDataReader
Dim Conn As SqlConnection = New SqlConnection
("Server=ServerStuff;Database=ffn;User
ID=pub;Password=sa;Trusted_Connection=False")
Dim dbComm As SqlCommand = New SqlCommand(sql, Conn)
Dim rs As SqlDataReader

Conn.Open()
rs = dbComm.ExecuteReader(CommandBehavior.CloseConnection)
Return rs
End Function
End Class
End Namespace

Compliled that, put it in the /bin directory, then Imported the namespace on
my page:
<%@ Import Namespace="DBSupport" %>

Here's where it might be shaky:
Dim testthing As new DBSupport.dataRdr
Dim sql as String = "SELECT * FROM All_Schools WHERE TeamName='FRONT'"
rs = testthing.OpenRDR(sql)
You should not be using include files in ASP.NET.
[quoted text clipped - 6 lines]
 
M

Marina

Did you recompile your project?
Is there a reason you are putting the code as a script instead of using the
code-behind model? This makes coding much easier and provides intellisense.

And one more note, it is standard practice that all class names begin with a
capital letter.
I'm also not quite sure why you are passing the string ByRef. Normally you
would only do that if the function were to modify the string and could not
return it as a result - though usually you can modify a function to return
an object that has a bunch of properties for all the return values. In this
case though, you are not modifying the string, and it is far more clear to
have it ByVal (which is the default) so the caller isn't wondering why it's
ByRef and if they should expect their string to be modified in some way.

And lastly, you might want a Try/Catch block in your function, so that if
any errors occur executing the query, you can close the connection.

Zak said:
Oh, and my current error is:

Compiler Error Message: BC30002: Type 'DBSupport.dataRdr' is not defined.

Source Error:

Line 82: <div style='position:absolute;top:420;left:192;height:10;width:
480;height:257;text-align:left' class='whitebg'>
Line 83: <%
Line 84: Dim testthing As new DBSupport.dataRdr
Line 85: Dim sql as String = "SELECT * FROM All_Schools WHERE
TeamName='FRONT'"

OK, I'm trying (big emphasis on trying) to make a class. Here is my vb
code:

Imports System.Data
Imports System.Data.SqlClient

Namespace DBSupport
Public Class dataRdr
Public Function OpenRDR(ByRef sql As String) As SqlDataReader
Dim Conn As SqlConnection = New SqlConnection
("Server=ServerStuff;Database=ffn;User
ID=pub;Password=sa;Trusted_Connection=False")
Dim dbComm As SqlCommand = New SqlCommand(sql, Conn)
Dim rs As SqlDataReader

Conn.Open()
rs = dbComm.ExecuteReader(CommandBehavior.CloseConnection)
Return rs
End Function
End Class
End Namespace

Compliled that, put it in the /bin directory, then Imported the namespace
on
my page:
<%@ Import Namespace="DBSupport" %>

Here's where it might be shaky:
Dim testthing As new DBSupport.dataRdr
Dim sql as String = "SELECT * FROM All_Schools WHERE TeamName='FRONT'"
rs = testthing.OpenRDR(sql)
You should not be using include files in ASP.NET.
[quoted text clipped - 6 lines]
are
welcome.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top