2

I have a small problem with my SQL Server and the connection I want to establish to it.

Here's my server:

SQL Server

Now I've tried to establish a connection, but it does not seem to work:

SqlConnection myConnection = new SqlConnection("user id=Admin;" +
                                   "password=PleaseWork;server=SQLEXPRESS" +
                                   "connection timeout=1");
try
{
    myConnection.Open();
}
catch (Exception e)
{
    catchExceptionBox.Text = e.ToString();
}

Unfortunately, since I have not yet worked with SQL Server, I do not know how to look up the IP of my server. Anyways, the error message I receive is a standard failed-connection message (which I receive after 14 seconds of trying to connect).

Any help would be appreciated.

5
  • 1
    Well, if you don't know the IP of your server, that is likely your issue, isn't it? Also, "connection timeout=1" seems pretty low. Commented Nov 19, 2015 at 14:13
  • 3
    Try using "localhost\SQLEXPRESS" as your server. Commented Nov 19, 2015 at 14:14
  • @GlorinOakenfoot Well, I thought using the name would suffice... I changed the timeout to 30, but still no change. Using localhost\\SQLEXPRESS also brought no change Commented Nov 19, 2015 at 14:17
  • 1
    Check out @Valentin's answer. You have a missing semicolon. Commented Nov 19, 2015 at 14:18
  • @GlorinOakenfoot Yes, I saw it. Thank you very much^^ Commented Nov 19, 2015 at 14:19

2 Answers 2

3

Are you missing ; after server=SQLEXPRESS?

Sign up to request clarification or add additional context in comments.

1 Comment

That brought indeed a change! Now it's just a failed login. Thank you very much!!
3

A SQL Server connection string should be along the lines of:

Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;

You are not specifying the database name. myServerAddress doesn't have to be the IP Address of your server and can be the name of your server instead.

www.sqlconnectionstrings.com/sqlserver is a good resource to use.

6 Comments

He is using SQL Server Express, so more like msdn.microsoft.com/en-us/library/jj653752(v=vs.110).aspx#sse
@Ernesto: I missed that. Good spot.
Thank you for your input. Regarding the database, I have not yet set up one (except if it sets up one by standard, but then I wouldn't know the name).
You also might need to set Integrated Security=False;to use username password.
I think it is false by default. It is only switched on when you set it to true.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.