Tuesday, December 28, 2010

Execute same SQL Server script in multiple databases

In one of my projects, same database schema is used in multiple databases for some practical reasons. Deployment is a challenging job in this case. We have 15 databases with the same schema. To overcome this issue, I have created a batch file which does job for us.

cls

rem Usage : DatabaseScripts <> <> <> <>
echo Welcome to Deployment Script
SET SOURCEFOLDER=%1
SET UserName=%2
SET Password=%3
SET ServerName=%4

IF /I "%SOURCEFOLDER%" == "" (
   ECHO "PATH TO SOURCE FOLDER NOT SPECIFIED".
   GOTO QUIT
)

IF /I "%UserName%" == "" (
   ECHO "User Name NOT SPECIFIED".
   GOTO QUIT
)

IF /I "%Password%" == "" (
   ECHO "Password NOT SPECIFIED".
   GOTO QUIT
)
IF /I "%ServerName%" == "" (
  ECHO "Server Name NOT SPECIFIED".
  GOTO QUIT
)

IF NOT EXIST "%SOURCEFOLDER%" (
   ECHO SOURCE FOLDER "%SOURCEFOLDER%" DOES NOT EXIST.
   GOTO QUIT
)

REM pass database names in for loop
FOR %%D IN (db1 db2 db3 db4) DO (
   sqlcmd -S %ServerName% -U %UserName% -P %Password% -d %%D -i %SOURCEFOLDER%\Deployment.sql -o %SOURCEFOLDER%\deploy_log_%%D.txt
)
ECHO "Deployed the script successfully"
pause

:QUIT
 
The above batch file accepts below parameters
 
  1. SOURCEFOLDER: Folder location where deployment script is located. It assumes that file name is Deployment.sql.
  2. UserName: UserName for the database
  3. Password: Password for the database
  4. ServerName: Database server Name

 After execution of the scripts, it will create log file for each database. Log files will be created in directory where the database deployment script is located.

Sqlcmd is a command line tool which can be used to deploy scripts in by reading from file.

Wednesday, December 22, 2010

How to access Self Signed Certificate from Windows Phone Emulator?

I am pretty new to Windows Phone development. I was trying to access a service which is on SSL. I spent good amount of time to access the service from my Windows Emulator. There is not much information on the net on this. Finally I could find the solution for this. I assume that you have self signed certificate available in your systems.

  1. Export Certificate
    1. On the server, open Internet Explorer, and click Tools --> Internet Options.
    2. In the window that comes up, click the Content tab, and then click the Certificates button.
    3. In the dialog that comes up, select the Trusted Root Certification Authorities tab. The self-signed certificate that you created should be visible. Select your Self Signed Certificate
    4. Click on the “Export…” button, then click the Next button. On the next screen, select “No, do not export the private key” (the default option) and click Next.
    5. On the next screen, choose the DER Encoded binary X.509 format (default option) and click Next.
    6. Finally, select the folder and enter your certificate name.
  2. Install certificate in Windows Phone Emulator
    1. Send created certificate to yourself in email. Could be your gmail or hotmail account.
    2. Open Windows Phone Emulator.
    3. Navigate to IE.
    4. Open the email which you sent to yourself.
    5. Click on the certificate name in the email.
    6. Then the emulator will allow you to install the certificate.
Now you should be able to access a service which is hosted on SSL(Self Signed).

 
Note: If the server is local system, then normally we use https://localhost/... In this case localhost does not work. Use machine full name instead of localhost. For example https://MyMachineName/service1.svc.


Note: For some reason I had to install the certificate twice to work on my system. It it happens to your system, you can do that same.  Self Signed certificate name must be host name.


Thursday, December 3, 2009

Webparts Vs Field Control

SharePoint provides opportunity to Content Owners to manage their content and avoids IT staff involvement in content management. This facility is called Web Content Management. Developers can create either Web Parts or Field Controls to provide this facility. Often developers get confused if they have to use WebParts or Field Controls. If developer makes wrong choice on this, it would impact drastically.

WebPart: Is a web widget, which can added to WebPart Zone on a web page. WebPart can be personalized, means each user can set his/her own preferences. We can create either SharePoint or ASP.Net Webpart to place on SharePoint webpage.
Field Control: Field controls are simple Microsoft ASP.NET 2.0 controls that you can create. They have a small amount of code to display the two modes of the controls: one for render time, and one for edit time. Windows SharePoint Services 3.0 and Office SharePoint Server 2007 provide several default field controls that you can use in your pages. We can extend any of the default Windows SharePoint Services 3.0 and Office SharePoint Server 2007 controls for your own specific functionality.


WebPart features:
  • Allow content owner to add webpart on Page Layout
  • Allow Content owner to move existing webparts on different webpart zones.
  • Personalize webpart for individual users.
  • We can create Editor Part for editing content.
  • Webpart content is stored in ASP.Net 2.0 personalization data store not as part of Page Layout.
Field Control Features:
  • All content pages, stored in their respective site's Pages library, conform to a speciic content type. content type defines the content fields on the page such as the title, subtitle, date, page body, and page image
  • As it is part of the Page Layout, Keep track of version history of the page. Allows user to revert back to older versions.
  • Do not allow content owner to add or move field controls on the page. This would restrict role of content owner for editing content only. Leaving structure and placement to Developers and Designers.
  • Since it is part of the Page Layout, seamless searching is possible.
  • Edit and View modes are integrated with Page Edit Toolbar. Developer can design the fields controls better since we can differentiate between Edit and View modes.
When to use field controls or Web Parts in publishing sites
Scenario
Field Controls
Web Parts
Centrally controlled site branding and user experience
X
 
Content owner responsible only for content, not presentation
X
 
Content owners need freedom to modify the layout of the page
 
X
Versioning of all content in site for historical or regulatory reasons
X
 
Personalization of content

X
Implementation of functionality (aggregating content from other sites or from same site)
 
X

Thursday, August 13, 2009

My First Blog

Hi,


This is my first blog post. Would try my best to share my knowledge to developer community.


Eswar Rao