Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

I think this is more of a connection string issue that MVC 3, so sorry in advance.

I've created a website in MVC 3 with the default database that is created when you register a new user. It works fine local but not on my web hosting where I receive the following error:

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)

The default connection strings are:

<connectionStrings>
    <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
  providerName="System.Data.SqlClient" />
    <add name="ASPNETDBConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True"
  providerName="System.Data.SqlClient" />

Should I specify a connection string with an explicit IP address of the server or retain the .\SQLEXPRESS command? If I need to specify a username and password then what should I use? I've never used a local SQLExpress database before so I'm clueless (which I'm sure is apparent).

share|improve this question
1  
On your web-hosting, where is the database installed? Does it even have SQL Express installed? –  BonyT Jul 21 '11 at 21:55
    
The database is in the App_Data directory. The web-hosting states "SQL Management Express Supported", but from the control panel I can't see any way of configuring it (nor do I know if configuration is necessary). I'm awaiting a reply from them, but wondered if it was a simple connection string issue instead. –  pfeds Jul 22 '11 at 3:41
    
It turns out the hosting provider doesn't support SQL Server Express, so I need to create a standard SQL database anyway. Thanks for the help. –  pfeds Jul 22 '11 at 5:06

3 Answers 3

up vote 2 down vote accepted

If you cannot use SQL Express, then you could consider an embedded SQL Engine:

SQL Compact Edition or SQLLite

I've never used SQL CE, but SQLLite is just a single DLL.

Obviously you don't have all the features of a fully fledged database engine, but they are still pretty powerful.

share|improve this answer
    
Excellent alternative, thanks. I'm not doing anything wondrous so SQLLite should be a nifty solution. Cheers. –  pfeds Jul 23 '11 at 5:13

Generally you will need use a connection string with a specific IP Address, Username, Password, etc.

Who are you hosting with? Generally a .net host provider will give you the connection string to use to connect to your database. You can copy and paste in to you web.config. Also, when they create the database for you, they generally specify the username, password, and database name so you will have to change all of that.

This is visual studio has Web.config.debug and Web.config.Release with the xml transformations. This way when you publish to the site, the connection string is automatically changed from your local connection string to the connection string used in your production environment.

share|improve this answer

You probably need to follow this article?

http://www.asp.net/mvc/tutorials/authenticating-users-with-forms-authentication-cs

Deafault ".net" installs Application Services to "AttachDBFilename=|DataDirectory|aspnetdb.mdf"

Then you create your own DB and now you're using two DB's to store data that could just be in one.

If you read the above article it shows you how to combine everything into one DB.

When you deploy to the hosting server (and it has a limit on how many DB's you can use or isn't even running sqlexpress) neither DB attach. So you need to make a "transform file" for your web.config file (usually Debug and Release) which is basically another web.config but only with the lines of config in that you need to change when the site is deployed to the hosting server.

So your hosting provider will give you the details needed for the connection string on the server. You then put that in the "web.config.release" file and when you compile and publish the "release" version of your site you will get a web.config file that has the correct connection string data in.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.