Results 1 to 12 of 12

Thread: [RESOLVED] Connection Object Error

  1. #1

    Thread Starter
    Addicted Member Tjoppie's Avatar
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    241

    Resolved [RESOLVED] Connection Object Error

    Hi all,,

    When I open a form where I refer to a public connection string, Visual studio tells me: The Variable 'JMSConnection' is either undeclared or was never asigned.

    The line which gives this is:

    VB Code:
    1. Me.SQLCon1.ConnectionString = JMSGlobals.JMSConnection.ConnectionString

    The connection string in the globals module is:

    VB Code:
    1. Module JMSGlobals
    2.     Public JMSColor = Color.FromArgb(149, 178, 198)
    3.     Public JMSConnection As New SqlConnection
    4.  
    5. End Module

    The connection string gets built in the login form and looks like:



    VB Code:
    1. Private Sub cmdLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLogin.Click
    2.  
    3.         If (RdoSQLAuth.Checked = True) Then
    4.             'JMSGlobals.JMSConnection.ConnectionString = "Server=" & Me.txtJMSServer.Text & ";Database=MSTRIBOLOGY;User ID=" & Me.txtUsername.Text & ";Password=" & Me.txtPassword.Text & ";Trusted_Connection=False;workstation id=" & Environment.MachineName & ";"
    5.             JMSGlobals.JMSConnection.ConnectionString = "Data Source=" & Me.txtJMSServer.Text & ";Initial Catalog=MSTRIBOLOGY;User Id=" & Me.txtUsername.Text & ";Password=" & Me.txtPassword.Text & ";Application Name=" & Application.ProductName & " " & Application.ProductVersion & ";"
    6.             Me.DialogResult = DialogResult.OK
    7.             'Me.Close()
    8.  
    9.         ElseIf (RdoNTAuth.Checked = True) Then
    10.             JMSGlobals.JMSConnection.ConnectionString = "Data Source=" & Me.txtJMSServer.Text & ";Initial Catalog=MSTRIBOLOGY;Integrated Security=SSPI;workstation id=" & Environment.MachineName & ";Application Name=" & Application.ProductName & " " & Application.ProductVersion & ";"
    11.             Me.DialogResult = DialogResult.OK
    12.             'Me.Close()
    13.         End If
    14.  
    15.     End Sub

    Anyone know where my problem might be?

    Thanks

    Rudi

  2. #2
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: Connection Object Error

    Maybe RdoNTAuth and RdoSQLAuth are uncheched....

    Regards
    Jorge
    "The dark side clouds everything. Impossible to see the future is."

  3. #3
    Fanatic Member
    Join Date
    Nov 2003
    Posts
    683

    Re: Connection Object Error

    Does it work, because I get the same notifications with my global variables I declare in a global module but the project still works. I have just ignored them.

  4. #4

    Thread Starter
    Addicted Member Tjoppie's Avatar
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    241

    Re: Connection Object Error

    Hmm.. Yeah it works, I figured the error is sql server related and not an error in my application. I think I'll just ignore them aswell

    Thanks

    Rudi

  5. #5
    New Member
    Join Date
    Jun 2005
    Location
    Concord, OH
    Posts
    12

    Re: [RESOLVED] Connection Object Error

    My suggestion is not to use Global Modules. Modules are a carry-over from VB6 - not very object-oriented at all.

    If you must use global variables for the connection string, create a class that is marked MustInherit so that you don't try to instantiate it. From within this class, create Public Shared objects. I don't recommend puting complex objects here because I think it muddies up the code, but if you need to, place a connection string within this class.

    As another alternative, I would create your own class that encapsulates all of your db connections and commands for your project. Instantiate this class when needed and pass references to the class object as needed.

    Finally, another interesting way to keep app data around within an app is to create a DataSet object with schema organized to store information such as db settings, applciation settings, user preferences. I liek doing this in some situations because if I need to dump these settings into a easily-read format, I can use the DataSet.WriteXML() function to easily dump the current applicaiton state to a file. Elegant and easy - plus you can then share these application settings between programs. If you're concerned with storing passwords in the xml files, then you could encrypt the output stream of WriteXML with the RijndaelManaged class before it's written to disk. After writing the encrypted file to disk, the user can carry aorund their settings file on a USB keychain in case they move between PCs.

  6. #6
    Fanatic Member
    Join Date
    Nov 2003
    Posts
    683

    Re: [RESOLVED] Connection Object Error

    Yeah I get them when I use a sqlselect statement with a global variable like
    Select * from table where Name = ' & globalvar & "'"

    Dunno how to fix it but the program works.

  7. #7
    Fanatic Member
    Join Date
    Nov 2003
    Posts
    683

    Re: [RESOLVED] Connection Object Error

    mikeismike

    Would you have an app example of this concept? I guess I am a legacy VB6 programmer because I have been using globals forever and always up to learning the newer, correcter way.

  8. #8
    New Member
    Join Date
    Jun 2005
    Location
    Concord, OH
    Posts
    12

    Re: [RESOLVED] Connection Object Error

    Yeah - I'll post one shortly - what concepts would you like to see in the sample app?

  9. #9

    Thread Starter
    Addicted Member Tjoppie's Avatar
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    241

    Re: [RESOLVED] Connection Object Error

    connection strings and extracting info like current sql user... etc... stuff about my server ;P

  10. #10
    Fanatic Member
    Join Date
    Nov 2003
    Posts
    683

    Re: [RESOLVED] Connection Object Error

    How you use what I call global variables. A variable that can be used and changed by different forms and then used in the sql selects. I would also be interested in the use of the connection strings. Obviously can be fake, I don't need yours but I would like to use the proper methodology for .net if globals are wrong.

  11. #11
    New Member
    Join Date
    Jun 2005
    Location
    Concord, OH
    Posts
    12

    Re: [RESOLVED] Connection Object Error

    Here's an example app with a few forms - I've forgone the encryption, but there's three sections: the Utility shared class I described, the dbconnection class that you could use, then the XML file application data form wher eit autoloads xml files to remember credentials when it opens.
    Attached Files Attached Files

  12. #12
    New Member
    Join Date
    Jun 2005
    Location
    Concord, OH
    Posts
    12

    Re: [RESOLVED] Connection Object Error

    Example app is VS 2003.

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