CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2012
    Posts
    1

    VB6 MSSQL Windows Authentication & Select Count in TextBox

    All,

    I am looking for an example of the windows authenticated connection to an MSSQL DB and a select count statement in a textbox in my form.

    I have this connection string:

    Code:
    Dim SQLCon As ADODB.Connection
    
     
    Set SQLCon = New ADODB.Connection
    
    With SQLCon 
    Provider=SQLOLEDB.1;Integrated Security=True;Initial Catalog=nautilus_MDB;Data Source=UKLONWPS3D01;Persyst Security Info=False;Command Properties='Command Time Out=45'" 
    End With
    Can I simply just paste this into my form_onload? Also how to I reference this connection when I then go to add my SQL query to textboxes etc?

    Does anyone have any example code they would be willing to share or take the time to explain this to me.

    Any replice will be much appreciated.

    Thanks,

    Ben.

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: VB6 MSSQL Windows Authentication & Select Count in TextBox

    The object needs to be dimmed in the context it will be used.

    For example if you dim and object [in this case the connection] in the form load then it can be referenced in the form load but would not be available to sub routines or functions outside the one where it is defined.

    If you dim it in the declarations section of the form then it will be available to all routines within the form.

    If you dim it in a module as public then it is available everywhere in your project.

    The key is to dim it as needed but try not to make the scope larger than you need for the task.

    The other code could go into form load reguardless of which location the object is dimmed.

    To get the result of your select statement you will also need to define a recordset and open it with your query and the connection then you can pull data from the recordset and stuff it into your text box.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: VB6 MSSQL Windows Authentication & Select Count in TextBox

    Also I doubt that your command under the "With" statement is not properly formulated.
    What you want is
    Code:
    With SQLCon 
      .Provider="SQLOLEDB.1;Integrated Security=True;Initial Catalog=nautilus_MDB;Data Source=UKLONWPS3D01;Persyst Security Info=False;Command Properties='Command Time Out=45'" 
    End With
    You were missing the period in front of Provider and the leading quotes.

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

Featured