Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Declaration Expected

Status
Not open for further replies.

onedizzydevil

Programmer
Mar 24, 2001
103
US
Using ASP.NET with VB.NET I am currently creating a Multi-Tier Web Application Module; however, when I am working between the Business Logic Layer (BLL) and the SQL Data Layer (SDL) I encounter a [tt]Declaration Expected[/tt] error.

I coded a [tt]Set Property[/tt] for the [tt]ConnectionString[/tt] variable in both the BLL and the SDL. The front-end designer will [tt]Set[/tt] the BLL [tt]ConnectionString[/tt] variable which will in turn [tt]Set[/tt] the SDL [tt]ConnectionString[/tt] variable which elimantes the need for the designer to directly communicate with the SDL.

I have an Imports of the SDL in the BLL; however, when I attempt to [tt]Set[/tt] the [tt]ConnectionString[/tt] variable I always get '[tt]Declaration Expected[/tt]'. This is a paste of the code I used.

---- BLL ----

[tt]Dim sdl As New SQLDataLayer()
sdl.ConnectionString = "Text"[/tt]


---- SDL ----

[tt]Private _ConnectionString As SqlConnection

Public Property ConnectionString() As SqlConnection
Set(ByVal Value As SqlConnection)
_ConnectionString = Value
End Set
End Property[/tt]

---- end ----

I see no reason why this should not work. Any ideas.

Wayne Sellars

"Programming, today is a race between software developers, striving to build bigger and better idiot-proof programs, and the Universe, trying to produce bigger and better idiots. So far, Universe 1 - Programmers 0."
 
Hey Wayne,

Something doesn't look right there to me. How are you assigning a string value ("text") to be of type SqlConnection and then assigning it to your _ConnectionString?

Shouldn't the connection string be of type string?

Jack
 
I tried it both ways it does not work either way, that was just the last thing I tried, it should be string.

---- SDL ----
Private _ConnectionString As String

Public WriteOnly Property ConnectionString() As String
Set(ByVal Value As String)
_ConnectionString = Value
End Set
End Property

Additionally, I could take the approach of Setting it in the BLL and then have the SDL Get it from the BLL if that is simplier. Wayne Sellars

"Programming, today is a race between software developers, striving to build bigger and better idiot-proof programs, and the Universe, trying to produce bigger and better idiots. So far, Universe 1 - Programmers 0."
 
I think I solve it, haven't fully tried it yet but it's not mad at me anymore. Will post back if for some reason it does not work.

---- BLL ----
Private _ConnectionString As String

' Value is set when an instance of object is created
Private Property ConnectionString() As String
Get
Return _ConnectionString
End Get
Set(ByVal Value As String)
Dim SDL As New Data()
_ConnectionString = Value
SDL.ConnectionString = _ConnectionString
End Set
End Property


---- SDL ----
Private _ConnectionString As String

Public Property ConnectionString() As String
Get
Return _ConnectionString
End Get
Set(ByVal Value As String)
_ConnectionString = Value
End Set
End Property

Wayne Sellars

"Programming, today is a race between software developers, striving to build bigger and better idiot-proof programs, and the Universe, trying to produce bigger and better idiots. So far, Universe 1 - Programmers 0."
 
Okay, after thinking about this some more, it should not be done this way and here is why.

I am creating an instance of the SDL but I am not closing (SDL = Nothing); therefore, I am leaving the instance open to communication with it. That is not a wise thing to do and could cause security as well as performance issues.

The solution is to create an instance of the SDL whenever it is needed and at the same time pass in the _ConnectionString. If you use the Constructors you can require the ConnectionString to be entered when an instance of the object is created therefore populating the _ConnectionString variable in the SDL instance and elminating the need for a user to directly accessing the SDL which allows for a completely independent Data Layer which means I could have a SQL Data Layer and an OLEDB Data Layer and switch them out as needed without the need to change anything in the Business Logic Layer as long an everything in the BLL handle the sending and receiving of data in generic way.

This is my first time creating a Class and Multi-Tier design so this may have been rather obvious to some people but here is skinny for those just trying to figuring it out like I am.

Wayne Sellars

"Programming, today is a race between software developers, striving to build bigger and better idiot-proof programs, and the Universe, trying to produce bigger and better idiots. So far, Universe 1 - Programmers 0."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top