Hello Friends....One more doubt...

I have a connection module in which I have written the open and close database connection....

if database connection is an error it will return false else if success it will return true

the function of the modules will be called from the form code....

what I need is if the connection is an error the module should also get the form name which returned the error...is it possible???

check my below code....

DBConnection.module

Imports System.Data.SqlClient

Module DBConnection
    Public Connection As SqlConnection = New SqlConnection()
    Public Function Open_DB_Connection() As String
        Try
            Connection.ConnectionString = "Data Source = LocalHost\;Initial Catalog = Database;Integrated Security  = True"
            Connection.Open()
            Return "Success"
        Catch ex As Exception
            MsgBox("Connection Error: " + ex.Message)
            Return "Fail"
            Exit Function
        End Try
    End Function

    Public Function Close_DB_Connection() As String
        Try
            Connection.Close()
            Return "Success"
        Catch ex As Exception
            MsgBox("Connection Error: " + ex.Message)
            Return "Fail"
            Exit Function
        End Try
    End Function
End Module

Call from the function is this way....

Dim Open_DB_Con As String
Dim Close_DB_Con As String

Open_DB_Con = Open_DB_Connection()

'other stuff required like queries....

Close_DB_Con = Close_DB_Connection()

now what I need is if the functions Open_DB_Connection() or Close_DB_Connection() returns error it should prompt the form name....

is it possible?? to code it in module....

thanks for help in advance....

What do you mean "Prompt the form name"?
And btw instead of returing string, rather return a boolean values - true of false.

prompt means display the form name which is showing the error.

Yes I have changed the string to boolean....

ok i will tell u in easy words....

I have one form say frmPatientRegister in which I need the connection string

module DBConnection

when the connection will fail it will contain false which will be passed to the module fail connection i.e. catch block...so I also want it to return the form name...

how to do that??

i think you can do like this, now here is sample you can do same with your close function ,

Public Function Open_DB_Connection(byval formName as string) As String
        Try
            Connection.ConnectionString = "Data Source = LocalHost\;Initial Catalog = Database;Integrated Security  = True"
            Connection.Open()
            Return "Success"
        Catch ex As Exception
            MsgBox("your " & formName & " has Connection Error: " + ex.Message)
            Return "Fail"
            Exit Function
        End Try
    End Function

now you can easily call this function like this .

Open_DB_Con = Open_DB_Connection("your from name")

hope this will solve your prob :)

best Regards

Muhammad Waqas Aslam

Great.....thank u very much Muhammad Waqas Aslam......it helped me a lot.....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.