views:

141

answers:

8

My sqlconnection is SqlConnection(@"Data Source = John\Administrator; Initial Catalog = TicketingSystem; Integrated Security = true;");

I try to connect to the server but i cant this error pops up A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

I think that the error is in the Data Source but I cant find it. When I open Microsoft SQL Server Management Studio it says that my server is "John" and the Connection is "John\Administrator" so please help me.

+3  A: 

if the server is actually called 'John', then that is your data source. When you're running locally, you could probably just set Data Source=(local), tho.

Other than that, you'd need to specify a user to connect with

http://connectionstrings.com/

David Hedlund
+1 Beat me by 1 second. He doesn't need to specify a user if he is using integrated security.
NYSystemsAnalyst
It seems almost certain that he's specifying a username for the data source. *Nonetheless*, "John\Administrator" *is* a valid data source, assuming the server is "John" and the instance name is "Administrator".
Adam Robinson
A: 

The Integrated Security=True part of your connection string means "connect as the current user". When you run an asp.net page, the current user by default is a special ASPNET account. You can "impersonate" a different user, but I'm guessing you haven't done that and the ASPNET user doesn't have access to your database.

Joel Coehoorn
He'd be receiving a different error if it were an access issue. I think "d." is correct.
Richard Szalay
A: 

It's possible that your server isn't configured to allow remote connections. You can check this in the SQL Server Configuration Manager tool.

Have a look here too.

Travis Heseman
A: 

Your Data Source is the server. So you only need "John", not "John\Administrator", that's not a valid data source. You're using integrated security which means it will use the same username as the program is running under and it's credentials, if it's on the domain.

Mystere Man
While it's likely incorrect, "John\Administrator" is absolutely a valid name. SQL Server supports multiple instances on a given server, and `\` is used to specify the instance. SQL Express is a perfect example of that, as it defaults to running as an instance called SQLEXPRESS.
Adam Robinson
+1  A: 

An easy way to get your connection string is

  1. create a file called x.udl
  2. double click on it
  3. Follow wizard
  4. open x.udl file in notepad
  5. and inside you will find your connection string.
John Nolan
+1 Wish I could do +10. Very nice.
J.Hendrix
+2  A: 

When I open Microsoft SQL Server Management Studio it says that my server is "John" and the Connection is "John\Administrator" so please help me.

That means you're logged on to your server's default instance (John) as Administrator. Remove the \Administrator part, and you should be good to go!

var cn = new SqlConnection(@"Data Source = John; Initial Catalog = TicketingSystem; Integrated Security = true;");
Arjan Einbu
+1  A: 

You can get your connectionstring from SQL Server Management Studio from the properties window.

Just click on the John\Administrator node, then press F4 to open the properties window, and search for the connection string there...

Arjan Einbu
A: 

Data Source = John\Administrator

Specifying John\Administrator as your Data Source, means ADO should connect to the SQL instance named "Administrator" on the server "John". Although instances are quite useful, I don't think that's what you want. (SQL Instances allow you to run multiple copies of SQL Server on one server)

As "d." mentioned, you will need to change Data Source to the correct server name or (local) ((local)\SQLEXPRESS if it's SQL Express).

Also, Integrated Security=true means that the user running ASP.NET, or at least the AppPool, will need access to the database. (The default is NETWORK SERVICE on pre-Windows 7, IUSR / IIS_USRS on 7).

If, however, you use ASP.NET windows authentication with <identity impersonate="true" /> then the user accessing the site will need access to the database.

Richard Szalay