Solved

My connection string does not connect when using username and password - SQL (Urgent)

Posted on 2016-08-02
7
32 Views
Last Modified: 2016-08-06
Hi

We have just replaced the server at a client and I am now trying to get my software to connect to the SQL database.

The connection string for the previous server was:

data source=MYSERVERNAME;initial catalog=dbHCA;persist security info=True;user id=myuser;password=mypassword;MultipleActiveResultSets=True;

This returns an error login failed for user 'myuser'.
Server authentication is set to both SQL and Windows

My user uses SQL server authentication and is mapped to dbHCA as a db_owner.
The properties look exactly the same as the previous server.

Am I missing something?

I did not setup the SQL server and we are using SQL server 2016.
Please let me know if you require more information.

As a side note: I can connect using integrated security
Data Source=MYSERVERNAME;Initial Catalog=dbHCA;Integrated Security=True
0
Comment
Question by:elmbrook
  • 4
  • 2
7 Comments
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
>>Am I missing something?

try to reset the password and use that new password in your connection string and try again?
0
 

Author Comment

by:elmbrook
Comment Utility
Thank you for your reply.
That didn't work.
0
 
LVL 49

Assisted Solution

by:Ryan Chong
Ryan Chong earned 500 total points
Comment Utility
so, whats the error message you receiving now? are you connecting to the correct server?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:elmbrook
Comment Utility
The error message is still the same.
login failed for user 'myuser'.

I am connected to the new server.
I have written a quick programme to test connection strings to the server (see code below)

this connection string connects
Data Source=MYSERVERNAME;Initial Catalog=dbHCA;Integrated Security=True
which tells me that I can connect to the server using Windows Authentication

this connection string
data source=MYSERVERNAME\;initial catalog=dbHCA;persist security info=True;user id=myuser;password=mynewpassword;MultipleActiveResultSets=True;
gives me the error which tells me SQL authentication is not working.

  private void button1_Click(object sender, EventArgs e)
        {
            string txt = textBox1.Text.Trim();
            SqlConnection thisConnection = null;
            thisConnection = new SqlConnection(string.Format( txt));

            try
            {
                thisConnection.Open();
                MessageBox.Show("Connected");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            textBox1.Text = "";
        }

Open in new window

0
 

Accepted Solution

by:
elmbrook earned 0 total points
Comment Utility
Oh man...I've been working on this for hours.
Finally, I followed Microsoft's Mantra - 'If all else fails...reboot' and guess what.
It works now...I am unsure why it never worked in the first place but thanks for your input.
0
 
LVL 26

Expert Comment

by:Zberteoc
Comment Utility
data source=MYSERVERNAME;initial catalog=dbHCA;persist security info=True;user id=myuser;password=mypassword;MultipleActiveResultSets=True;

I would remover "persist security info=True;" part.
0
 

Author Closing Comment

by:elmbrook
Comment Utility
Reboot worked...Thanks for the help.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now