Monday, June 22, 2009

How to create Dropdownlist control for a SQL datasource using Sharepoint Designer

By default when you open a SQL datasource , and drag and drop the view to create a Input form for that datasource, the sharepoint point creates all fields as Text Boxes. This is not what a normal user wants.It would be greate when he can't choose a value from a dropdown and thus reduces the chances of duplicate records or wrongly spell words in the SQL tables.

Thus I have recreated the textbox control to dropdown, remember the main trick is
changing the textbox control to sharepoint inbuilt dvdropdownlist and change the binding to
'SelectedValue','SelectedIndexChanged'


<asp:SqlDataSource runat="server" id="SqlDataSource1" ConnectionString="Data Source=bwcmossdev;Initial Catalog=bwcSalesExec;User ID=sa;Password=webtech@123" ProviderName="System.Data.SqlClient" SelectCommand="SELECT rtrim(SALESMOT_SalesTeams.SalesTeamName) [SalesTeamName], SALESMOT_SalesTeams.SalesTeamManager, SALESMOT_SalesTeams.IsActive, Global_DivisionsNLocations.Description, SALESMOT_SalesTeams.SalesTeamID FROM SALESMOT_SalesTeams INNER JOIN Global_DivisionsNLocations ON SALESMOT_SalesTeams.SalesTeamDivision = Global_DivisionsNLocations.GlobalLocationId where SALESMOT_SalesTeams.isActive =1" />

<SharePoint:DVDropDownList runat="server" id="ff2{$Pos}" __designer:bind="{ddwrt:DataBind('i',concat('ff2',$Pos),'SelectedValue','SelectedIndexChanged','',ddwrt:EscapeDelims(string('')),'@SalesTeamID')}" selectedvalue="{@SalesTeamID}" datasourceid="SqlDataSource1" datatextfield="SalesTeamName" datavaluefield="SalesTeamID" />

Monday, June 15, 2009

Content DB Restore by SQL DB move, showing zero sites

First of all i'll tell you the steps how to copy your existing Site DB to a new Server.
STEP1: BACKUP:

  1. On Source SQL Server: Backup SharePoint Content databases.
  2. Open SQL Server Enterprise manger
  3. Right Click a database (For ex: WSS_Content)>All Tasks>Backup Database>Database Complete>Backup to disk>Add>Filename>Provide a path & filename>Ok>Ok
Question:How to find name of Content databases:
Central Admin>Application Management>Content databases>Select web application from Right Hand Side Top drop down list
Database name will be displayed.

Step 2:Prepare the destination SQL server and Web server.

  1. Install the same versions of Service Packs for SQL and MOSS 2007, similar to your production server.
  2. Ensure you use the similar Admin user which would have full access as service account for both Web server and SQL server. (Check Security Administrators & Database Creators)
Step 3: RESTORE CONTENT DATABASE TO DESTINATION SERVER
  1. Copy backup Content database files to Destination SQL Server
  2. Open SQL Server Enterprise manger
  3. Create a database in your destination SQL, give the same name that of your backed up DB
  4. Databases>Right Click>All Tasks>Restore database>Restore as Database>Type name of Content Database>From device>Select device>disk>Add>Browse to backup files>Ok>
Step 4: RESTORING SITES FROM DATABASES
  1. Create a new web application http:// at port 80 with content database name WSS_Content_TEST ( this Database we will remove and replace with out backed up DB)
  2. Go to V3 Central Administration Page>Application Management>Create or extend Web Application
  3. Click on Create a new web application
  4. Choose any unused port no you can fancy
  5. Enter Database Server Name and enter Database name as WSS_Content_TEST
  6. Wait for operation to complete
  7. After application is created create a site collection, ( you can give any name eventually it'' not be used)
  8. Fill the details and select Team site template click Ok
  9. Browse to test site http://
  10. Check if it is working

    To remove WSS_Content_TEST from a web application
  11. Go to Central Administration, Central Administration > Application Management > Click on Content Databases
  12. On right hand side select the newly created web application if not already present
  13. Click on Database name WSS_Content_TEST
  14. Check remove content database checkbox and click OK

    To attach restored content database to a new web application:
    Open a command prompt and browse to
    c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Bin>
    Run following command
    stsadm -o addcontentdb -url http:// -databaseserver Mossdev -databasename BackupDBName -assignnewdatabaseid
    Where Mossdev is my Database server name
    BackupDBName is my BackedUp Database that i've restored in SQL.

    Check if the sites collection has be restored in your new server

  15. Go to Central Administration, Central Administration > Application Management > Click on Content Databases
  16. On right hand side select the newly created web application if not already present
  17. Check the No. of sites in the site collection if its showing same no. that you had in your Restored Content DB webapplication.
  18. Then you are done with it. check the URL of the application, to view your restored Sharepoint Site.
Note: If still the new restored Content DB is showing "Current Number of Sites" is 0
Then there might be an existing Content DB id in your sharepoint installation configuration DB.
Here is the workaround. First find out the Id of the sites (site collection) in the [restored_db].Sites then delete the line in the [Config_db].SiteMap with the same Id. Now attach the content_db and you should see the sites.
Or what you can do is change the ID inside the [config_db].SiteMap to something else, maybe change a number.