4

So I am moving a DNN7 website from my local computer (the site has been developed in WebMatrix) to a Server running Windows Server 2008.

When I run the site I get the error. 'DNN Error Connection To The Database Failed'.

Now the strange thing is I downloaded Webmatrix on the 2008 Server and got the site to run fine, but running from IIS it does not work.

Why would it work for Webmatrix but not IIS?

Edit: My connection string is:

<add name="SiteSqlServer" connectionString="Server=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|Database.mdf;Database=DNN2;Trusted_Connection=Yes;" providerName="System.Data.SqlClient" />

Any thoughts why this connection string wont work?

I keep getting 'Connection to the database failed.

Thanks

James

  • Are you using Integrated Security when connecting to your database? If so, then when hosting it in IIS it will use the Application pools identity to connect to the SQL server. Create a sql user and then change your web.config to use a user id; password when connecting to your DNN Database. – Ryan Gunn Oct 22 '13 at 08:24
  • Does it matter that I am using SQL Express? I tried adding the user I created for the app pool but no change. – James Michael Lucas Oct 22 '13 at 08:39
  • It's shouldn't matter if you are using SQL Express. – Ryan Gunn Oct 22 '13 at 09:20
  • Adding a user and password does not seem to have changed anything. Does the connection string have any anomalies? – James Michael Lucas Oct 22 '13 at 09:36
  • You have integrated security set to True, that won't allow the username/password to work, that'll use the application pool – Chris Hammond Oct 22 '13 at 14:12

1 Answers1

3

Please make sure you update both SiteSqlServer settings in your web.config. Look below to see an example. One is under <connectionStrings> and the other under <appSettings>

      <connectionStrings>
        <add name="SiteSqlServer" connectionString="Server=myServerName;Database=myDataBase;User Id=myUsername;
Password=myPassword;" providerName="System.Data.SqlClient" />
      </connectionStrings>

      <appSettings>
        <add key="SiteSqlServer" value="Server=myServerName;Database=myDataBase;User Id=myUsername;Password=myPassword;" />
      </appSettings>

Hope this helps

Ryan Gunn
  • 1,161
  • 7
  • 18
  • Thanks, I have kept both of them the same throughout. Also I am using SQL express and using a database in the APP_DATA folder so should I need a user name and password? – James Michael Lucas Oct 22 '13 at 15:38
  • My mistake, forgot you were using an attached db file. You would need to use a username and password then. Have you tried using this "Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;Database=dbname; Trusted_Connection=Yes;" – Ryan Gunn Oct 23 '13 at 05:33
  • I used this layout and it still cannot find a connection to the database. I opened the project in webmatrix and it works there with a connection (although it changed from what I had written. Edit: Apologies I opened the wrong one, this project does not work in webmatrix. – James Michael Lucas Oct 23 '13 at 08:28