Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Distributed Applications / December 2005

Tip: Looking for answers? Try searching our database.

Reusing code across multiple projects in distr app

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ross - 13 Dec 2005 12:27 GMT
Hi folks

I am building this distributed app that has a number of Web Service Projects.

A common task is to  connect to a DB with code that looks like this:

Dim cn As SqlConnection
       Dim strInfo As String

       strInfo = "server=(local);Persist Security
Info=False;pwd=;Integrated
Security=SSPI;database=FusionCommunityVolunteerService;Connect Timeout=30"

       Try
           cn = New SqlConnection
           With cn
               .ConnectionString = strInfo
               .Open()
           End With

           Return cn

       Catch ex As Exception

       Finally

           If cn.State <> Data.ConnectionState.Closed Then
               cn.Close()
               cn.Dispose()
           End If
       End Try

I was thinking that it would be good both from a programming time viewpoint
and also in terms of code maintainability if I could have a func procedure
that does exactly that and could be called from any procedure in any of the
projects in the Solution.

What is the best way to do this?  Any advice would be muchly appreciated.

Kind regards

Ross Petersen
binvij - 13 Dec 2005 13:23 GMT
Hi Ross,

I believe, for the said scenario, Data Access Application blocks will be a
viable option.

thnks
Signature

Bindesh Vijayan
MCP [ASP.NET]

> Hi folks
>
[quoted text clipped - 38 lines]
>
> Ross Petersen
Ross - 13 Dec 2005 19:27 GMT
Thanks Bindesh

So, how do I do that?  

Could I just create a Class Module and create the procedure in that module
using the "Friend" keyword?  Or would there be a better approach?

Also, in respect to the "Finally" section in the Try ... End Try block, is
this part OK:

> >             If cn.State <> Data.ConnectionState.Closed Then
> >                 cn.Close()
> >                 cn.Dispose()
> >             End If

Kind regards

Ross Petersen

> Hi Ross,
>
[quoted text clipped - 45 lines]
> >
> > Ross Petersen

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.