Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2016-08-02
7
Medium Priority
?
52 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 53

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 53

Assisted Solution

by:Ryan Chong
Ryan Chong earned 2000 total points
ID: 41738566
so, whats the error message you receiving now? are you connecting to the correct server?
0
How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

 

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 27

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

Setting up LaraDock for Laravel

Learn how to set up LaraDock in a Laravel project - LaraDock gives us an easy way to run a Laravel application using Docker in a single command.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

670 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