Monday, March 16, 2009

Essential reading if you are trying to run DNN5 with a proper SQL Server Express Connection String...

This blog post has just saved me lots of horrible experimentation

http://www.dotnetnuke.com/Community/Blogs/tabid/825/EntryId/1202/DNN-SQLExpress-SQL-Server-Management-Studio.aspx

Basically I've been running using "File" access - and now it's definitely time to move up to "proper" access. For a start it will make my backup process 100 times easier :)

Post is reproduced here - just so it can go missing in any reorg at DNN:

Recently I rebuilt my laptop and decided to only install SQL Express and not the full SQL Server 2005.  The issue I can across occurs when you attach to the DNN mdb file within SQL Server Management Studio.  Once you have done that the connection string does now work and you DNN site cannot connect to the database. And no matter what you do you cannot correct it even by detaching it, restart SQL Express, resetting IIS, etc.  I finally had to scrap the database and do it all again.  Below is the way to setup DNN and SQL Express if you want to also access the database from within SQL Server Management Studio.

1) Rename the Database.mdb to another name.  (This is optional).

2) Open SQL Server Management Studio and do the following 
  • Attach the database 
  1. Right click on the database folder and choose attach.
  2. Click Add button and point to the database you want to attach to.
  3. Click on the "Attach As" column and give it a more friendly name.  For this blog purpose we will change it to DotNetNuke_ModDev
  4. In the lower screen delete the line that references the ".ldf" file.  This will be created and you will get an error that it cannot be found if you do not delete it.
  5. Click on the "Current File Path" for the ".mdf" file and update it so it points to the location of the DNN database you are attaching to.
  6. Click Okay and the database should be attached correctly.
  • Set up permissions
    • Adding Login
      1. Click on the security\logins folder.
      2. If the ASPNet user exist you can skip this section.
      3. Right click login folder and choose "New Login"
      4. Click the "Search" button, then the "Advance" button, and then the "Find Now".  This will bring up a list of user on the computer and select the ASPNet account.
      5. Make sure Windows authentication is checked and click "OK" to add user.
    •  Adding Database User
      1. Click on "Databases\Security\Users folder.
      2. If the ASP.Net user exist you can skip this section
      3. Right click the user folder and choose "New User"
      4. Click on the "..." button next to the Login Name, then click on the "Browse" button.
      5. Check the ASPNet user and click "OK" button.  Click the OK button on the Select Login screen and this will add the user.
      6. Under database role membership check one of the following combinations.  Option #2 is more secure.  Click "OK" button when done.
        • Permission Options #1
          • dbowner
        • Permission Options #2
          • db_datareader
          • db_datewriter
          • db_ddladmin
          • db_securityadmin
    • Setting Database Permissions (Only needed it Option #2 is chosen above)
      1. Right click on the database you attached to and choose "Properties"
      2. Click on "Permissions" under select a page (upper-left of screen).
      3. Under Explicit permission for {Database Name}, make sure that the Grant box is checked for Execute.
3) Update the connection strings in the DNN web.config file.  Do not forget to use the same connection string in the <ConnectionString> and <AppSettings> section.

FROM
Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|Database.mdf;

TO

Data Source=.\SQLExpress;Integrated Security=True;User Instance=False;Database=DotNetNuke_ModDev;

4) Access the DNN web site to run the installation process.

You should now have a working DNN site and a SQL Express database that you can access/manipulate using SQL Server Management Studio and still be able to access it from the web site as well.

No comments:

Post a Comment