Results 1 to 3 of 3

Thread: Something is amiss with my connection string

  1. #1

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Something is amiss with my connection string

    I've been using a SQLCE database for some of my smaller projects, but decided to use a normal SQL database for a new project that is going to contain a large amount of information.

    Since I realize that the connection strings for a SQLCE database and a SQL database, I decided to go to connectionstrings.com to find out what needs to be used for SQL.

    I found this:

    SQL Code:
    1. Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

    Although it does give me the proper string, it doesn't really give a good explanation of how to apply it.

    Originally, I tried setting the Data Source to the location of my database, which is local for now. Then I set the Initial Catalog to my database name. There isn't a password or user ID for the database so I didn't include those:

    VB.NET Code:
    1. Dim connection As New SqlConnection("Server=C:\Users\Ernest\Desktop\; Data Source=dbCredentials.mdf;")

    Any ideas on what I'm doing wrong?

    Thanks
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  2. #2

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Something is amiss with my connection string

    I didn't realize that VS automatically created connection string for me. It turns out that it is this:

    VB.NET Code:
    1. Dim connection As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Ernest\Desktop\dbCredentials.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")

    Now that the connection error is gone, I have another error. The code below is being used from a post JMC made a little while back to validate login credentials:

    vb Code:
    1. Dim connection As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Ernest\Desktop\dbCredentials.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
    2.  
    3.         Dim command As New SqlCommand("SELECT COUNT(*) FROM Users WHERE UserID = @UserID AND Password = @Password", _
    4.                                       connection)
    5.  
    6.         With command.Parameters
    7.             .AddWithValue("@UserID", Me.txtUserName)
    8.             .AddWithValue("@Password", Me.txtPasssword)
    9.         End With
    10.  
    11.         connection.Open()
    12.  
    13.         If CInt(command.ExecuteScalar()) = 0 Then
    14.             MessageBox.Show("Invalid credentials!", "ISTme! Login", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    15.         Else
    16.             Me.DialogResult = Windows.Forms.DialogResult.OK
    17.         End If
    18.  
    19.         connection.Close()

    When it gets to the ExecuteScalar line, it throws an exception:

    No mapping exists from object type System.Windows.Forms.TextBox to a known managed provider native type.
    Does this mean I have to save the credentials to a variable first and then pass it as a a parameter?

    I don't have time to check it out at the moment.

    Any information is appreciated.

    Thanks
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  3. #3

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Something is amiss with my connection string

    I feel silly. I assigned the TextBox to the Username/Password, but not the text property.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

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