Ask a Question related to ASP.NET General, Design and Development.
-
VB Programmer #1
Re: Question: ConnectToDatabase function
Thanks! I wasn't sure if the Try code would continue or not if an exception
was "caught". Now I know it doesn't.
"Marina" <mzlatkina@hotmail.com> wrote in message
news:u7IKm0QYDHA.2548@TK2MSFTNGP09.phx.gbl...String)> There is no need to check if the connection is open. It can't be, you just
> created it.
>
> I would write it in the following way:
>
> Public Function ConnectToDatabase(ByVal strConnectionString As String)
> As Boolean
> Try
> cnnMyConnection = New SqlConnection(strConnectionString)
> cnnMyConnection.Open()
>
> Return True
> Catch ex As Exception
> HandleError(ex, "SqlDataHelper.ConnectToDatabase")
> Return False
> End Try
>
> End Function
>
>
> "VB Programmer" <growNO-SPAM@go-intech.com> wrote in message
> news:e0i28vQYDHA.384@TK2MSFTNGP12.phx.gbl...> the> > I created a custom utility function called ConnectToDatabase, which does
> > just that. It should return True if it went ok, False if not. Is this> Return> > most efficient code or is there an easier way (esp in regards to the> > value)?
> >
> > Private cnnMyConnection As SqlConnection
> >
> > Public Function ConnectToDatabase(ByVal strConnectionString As>> > As Boolean
> > Dim bSuccess As Boolean = True
> >
> > Try
> > cnnMyConnection = New SqlConnection(strConnectionString)
> > If cnnMyConnection.State <> ConnectionState.Open Then
> > cnnMyConnection.Open()
> > End If
> > Catch ex As Exception
> > HandleError(ex, "SqlDataHelper.ConnectToDatabase")
> > bSuccess = False
> > End Try
> >
> > If bSuccess Then
> > Return True
> > Else
> > Return False
> > End If
> > End Function
> >
> >
>
VB Programmer Guest
-
IIF function question
I'm studying for my ColdFusionMX exam using Ben Forta's study guide. There is quite a bit of errata in the book, including code that simply doesn't... -
Function Question
Hi! Is there a considerable degredidation in speed if I where to include an ASP page into every other ASP page that would contain all the... -
Simple AS function question
Why will this not work home_btn.onRollOver = setInterval(delayAction,2000,home); function delayAction (framename:String) var name:String =... -
PHP function question
When writing a function that takes in a variable number of parameters and processing it using func_get_args or a similar technique, I'm assuming... -
utf8_decode function question
Hi folks, I read in a security note that something known as a cross-site scripting attacker can use utf8 encoding and that you could decode data to...



Reply With Quote

