1

I'm moving from a shared hosting to Virtual Dedicated Server (both at GoDaddy). Suprisingly, everything went fine up until now. However, now my web application seems unable to connect to the database (which I created on the server).

I tried several options, including giving it the server name etc. for example:

<add name="dbname" connectionString="Data Source=servername\SQLEXPRESS2008;Initial Catalog=theDB;User Id=servername\usernameAcceptedByMangmentStudio;Password=mypwd; Trusted_Connection=False;"/>

also:

<add name="dbname" connectionString="Data Source=.\SQLEXPRESS2008;Initial Catalog=theDB;User Id=usernameAcceptedByMangmentStudio;Password=mypwd; Trusted_Connection=False;"/>

also:

<add name="dbname" connectionString="Data Source=servername\SQLEXPRESS2008;Initial Catalog=theDB; Integrated Security=True;>

(this is how it works on my local machine).

nothing seems to work. any ideas? thanks in advance.

dsb
  • 2,347
  • 5
  • 26
  • 43

2 Answers2

2

It seems you don't know whether you have a named instance or a default instance. Or even the difference between the two.

First I'll explain the quickest way to determine which you have, then I'll explain the differences.

You need to connect to your server (I assume you can remote desktop or something similar), then open Control Panel > Administrative Tools > Services. In that list there should be an item called SQL Server, and it will either look like this:

SQL Server (MSSQLSERVER)

Or this:

SQL Server (some_name)

The former is a default instance. If this is what you see, then the connection string should be:

"Data Source=localhost;..."

The latter is a named instance. If this is what you see, your connection string should be:

"Data Source=localhost\some_name;..."

If you see both, then you need to tell us how you initially connected to this instance in order to create the database (and you need to decide which one you want to use, since you probably don't need both).

If that doesn't help, you need to be more specific than "doesn't work." Are you unable to connect to the server, or the database? What is the actual error message? When you created the database, did you use the User Instances / AttachDbFileName features? Can you show a screen shot of the connection dialog in Management Studio that is successful? Is your app on the server or on your local machine? Is it possible you should be specifying the IP address instead of various local references? Have you contacted GoDaddy support about your problem? They are far better equipped to help you than a programming Q&A site, since they can connect to your server in 10 seconds and tell you exactly how you should be referencing the SQL Server instance.

As for the differences, named instances are typically used when you need to install multiple individual instances of SQL Server. This is not usually a requirement on a production machine; much more common on development machines where you must test multiple versions, simulate different environments, or temporarily during a migration or side-by-side upgrade. A default instance listens out of the box on port 1433. Named instances run on other ports and usually use the SQL Browser service for remote machines to identify how exactly to connect to them.

Aaron Bertrand
  • 272,866
  • 37
  • 466
  • 490
  • thank you so much for this extensive illuminating explanations. +1 for being so kind and helpful. Now I managed to install and run the application on the server (i.e., locally using remote desktop), the wierdest thing. after trying several connection strings I used the simplest one: . Now, running using debugger everything works fine. but approaching the website using browser from another computer I don't get information. I'll keep on checkin – dsb May 31 '12 at 15:20
  • If you're on another computer, you can't say `.` - that means local. How is your other server supposed to find your database server? Might it also find my database server if you're just saying go out to the Internet and find any SQL Server? You need to specify the IP address or fully-qualified domain name of the server where SQL Server is running. So it should be something like `"Data Source=45.34.22.12\SQLEXPRESS2008;...` You may also need to go onto the database server and be sure to enable TCP/IP (in SQL Server Config Mgr), allow remote connections, and open the right firewall port(s)... – Aaron Bertrand May 31 '12 at 15:27
  • Thank you so much for all the help. working with debugger i found that the problem was that i had no permitted user to the database (working locally i could connect with windows credentials). sorry for my lack of knowledge, i'm novice to all this. after finding out how to define a user everything works now. Thank you very much, you've been an enormous help! – dsb May 31 '12 at 17:45
  • @user739809 glad to help. You should accept the answer and we can all move on. :-) – Aaron Bertrand May 31 '12 at 17:49
0

If your DB has UserName and Password(SQL Server Authentication) just simply use this:

<add name="dbname" connectionString="Data Source=yourServerName;Initial Catalog=YourDB;User ID=YouruserId;Password=YourPassWord" providerName="System.Data.SqlClient"/>

FYI: Make sure your database Server Authentication is SQL Server and WindowsAuthentication mode

You can check also : Connection strings for SQL Server 2008 for more info.

Regards

BizApps
  • 6,048
  • 9
  • 40
  • 62