Solved

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

Posted on 2016-08-02
7
41 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 51

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 51

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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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…
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

762 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