Last post Mar 06, 2013 11:36 AM by DanielWayne
Mar 06, 2013 12:09 AM|DanielWayne|LINK
I am just
learning about razor syntax, and I am trying to work with a trivial mdf database in my website App_Data folder. Everything works fine under Visual Studio 2010 server. But when I move my application to a live server with IIS, it fails. Now this live IIS server
hosts some applications that connect to a separate MS SQL database, and that works fine. But my goal is to get some razor applications working with a database as part of the project.
I troubleshoot this? Thanks in advance for any suggestions!
Here is my database code in my Default.cshtml page, and this
works fine under Visual Studio 2010 server:
Layout = "~/_SiteLayout.cshtml";
Page.Title = "Welcome to my Web Site!";
var db= Database.Open("startersite");
var sqlQ = "SELECT * FROM table1";
var data = db.Query(sqlQ);
Here is the error that I get when I move the application
to the live IIS server:
Error in '/test001' Application.
An unhandled exception occurred during the execution
of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
System.Data.SqlClient.SqlException: 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)
Mar 06, 2013 03:36 AM|Abhishek Luv|LINK
Are you using SQL Server CE db or SQL Server db which is at your hosting server?
Mar 06, 2013 05:13 AM|GmGregori|LINK
You could have a problem with the connection string in your Web.config file.
Look at it: it should include a section like
<add connectionString="Server=InstanceName;Database=DatabaseName;Integrated Security=true" name="startersite" providerName="System.Data.SqlClient" />
(my example refers to a trusted collection).
For more examples of connection strings look at this site:
Mar 06, 2013 11:36 AM|DanielWayne|LINK
Ok, now I am beginning to understand. Y'alls comments helped direct me to more useful research, and I get it now. With what I was attempting, I would need to replicate the database on the live MS SQL server (MS SQL serve and not the compact edition in
this case). I was thinking Visual Studio would just copy over a database, but it doesn't work that way. I noticed that because the web.config connection string had 'sqlexpress' which is obviously not going to work on the live server. I know how to make this