John
John

Reputation: 1

SqlConnection problem

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.

Upvotes: 0

Views: 1390

Answers (9)

jidajez
jidajez

Reputation: 41

  1. Create a file called x.udl
  2. Double-click on it
  3. Follow the Wizard
  4. Open x.udl file in notepad

and then you will find your connection string inside.

Upvotes: 0

Richard Szalay
Richard Szalay

Reputation: 84724

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.

Upvotes: 0

Arjan Einbu
Arjan Einbu

Reputation: 13672

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...

Upvotes: 1

Arjan Einbu
Arjan Einbu

Reputation: 13672

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;");

Upvotes: 2

Johnno Nolan
Johnno Nolan

Reputation: 29659

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.

Upvotes: 3

David Hedlund
David Hedlund

Reputation: 129782

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/

Upvotes: 3

Erik Funkenbusch
Erik Funkenbusch

Reputation: 93424

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.

Upvotes: 0

Travis Heseman
Travis Heseman

Reputation: 11449

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.

Upvotes: 0

Joel Coehoorn
Joel Coehoorn

Reputation: 415600

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.

Upvotes: 0

Related Questions