Solved

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

Posted on 2016-08-02
7
38 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 50

Expert Comment

by:Ryan Chong
ID: 41738562
>>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
ID: 41738565
Thank you for your reply.
That didn't work.
0
 
LVL 50

Assisted Solution

by:Ryan Chong
Ryan Chong earned 500 total points
ID: 41738566
so, whats the error message you receiving now? are you connecting to the correct server?
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

Author Comment

by:elmbrook
ID: 41738570
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
ID: 41738580
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
ID: 41739153
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
ID: 41745365
Reboot worked...Thanks for the help.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

840 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