|
-
Jun 27th, 2010, 12:39 PM
#1
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:
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:
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
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Jun 27th, 2010, 01:25 PM
#2
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:
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:
Dim connection As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Ernest\Desktop\dbCredentials.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True") Dim command As New SqlCommand("SELECT COUNT(*) FROM Users WHERE UserID = @UserID AND Password = @Password", _ connection) With command.Parameters .AddWithValue("@UserID", Me.txtUserName) .AddWithValue("@Password", Me.txtPasssword) End With connection.Open() If CInt(command.ExecuteScalar()) = 0 Then MessageBox.Show("Invalid credentials!", "ISTme! Login", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Else Me.DialogResult = Windows.Forms.DialogResult.OK End If 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
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Jun 27th, 2010, 03:05 PM
#3
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
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|