Results 1 to 3 of 3

Thread: Public Sql

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Posts
    208

    Public Sql

    Hi,

    I have 10 forms and on EACH form I have done

    dim cn as new adodn.connection

    Form Load event

    If cn.State <> 1 Then
    cn.Open "Provider=SQLOLEDB.1;User ID=administrator;Initial Catalog=Meridian;Data Source=administrator"
    End If
    cn.CursorLocation = adUseClient


    On each of the forms I have written the connection open string

    Is there a way where I can write it only once and it works
    for all forms ????

    If yes where n how ?

    Pls advice

    thnks

  2. #2
    Fanatic Member holly's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere on earth
    Posts
    721
    Why not place it in a public module and then call each connection

    ie call serverconnectins


    HTH
    ** HOLLY **

  3. #3
    Fanatic Member holly's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere on earth
    Posts
    721
    Example of module

    VB Code:
    1. Public m_objoCn As ADODB.Connection
    2.     Public m_strCS As String
    3.  
    4.     Public Sub Initialiseserverconnection()
    5.  
    6.     On Error GoTo OpenErr:
    7.  
    8.     Set m_objoCn = Nothing
    9.     Set m_objoCn = New ADODB.Connection
    10.        
    11.         m_strCS = "Provider=SQLOLEDB.1;"
    12.         m_strCS = m_strCS & "Data Source=;"
    13.         m_strCS = m_strCS & "database=_;"
    14.         m_strCS = m_strCS & "user id=;"
    15.         m_strCS = m_strCS & "password=;"
    16.         m_strCS = m_strCS & "Use Procedure for Prepare=1;"
    17.         m_strCS = m_strCS & "Auto Translate=True;"
    18.         m_strCS = m_strCS & "Packet Size=4096;"
    19.  
    20. 'Open the Connection
    21.     With m_objoCn
    22.         .ConnectionString = m_strCS
    23.         .CursorLocation = adUseServer
    24.         .Open m_strCS
    25.     End With
    26.  
    27.         Exit Sub:
    28. OpenErr:
    29.     MsgBox Err.Description, vbCritical
    30.  
    31. End Sub
    ** HOLLY **

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width