Thursday, June 20, 2013

How to Check if another instance of the application is already running


how it is possible to check whether another instance of the program is running and if so stop the application before loading if there is an existing instance of it.

Solution:


write at your Main method the following code to quit the method which will kill the currently loading process instantly.

if (System.Diagnostics.Process.GetProcessesByName(
 System.IO.Path.GetFileNameWithoutExtension(
  System.Reflection.Assembly.GetEntryAssembly().Location)).Length > 1)
 {
  MessageBox.Show("Application is already running");
  System.Diagnostics.Process.GetCurrentProcess().Kill();
 

How to: Reset the Visual Studio 2010 Environment Settings


To reset your Visual Studio settings:

1. From the Tools menu, click Import and Export Settings.



2. On the Welcome to the Import and Export Settings Wizard page, click Reset all settings and then click Next.


3. If you want to save your current settings combination, click Yes, save my current settings, specify a file name, and then click Next.
—or—
If you want to delete your current settings combination, choose No, just reset settings, overwriting my current settings, and then click Next. This option does not delete default settings, which will still be available the next time you use the wizard.


4. In Which collection of settings do you want to reset to, select a settings collection from the list.


5. Click Finish.
The Reset Complete page alerts you to any problems encountered during the reset.

---------------------------------------------------------
There are a couple of command line options to reset the environment
The command "devenv /resetsettings" will restore Visual Studio back to its original factory state. 

How to: Install Microsoft SQL Server 2008 Step by Step


The system requirements are as follow:
  • 32-bit systems: Computer with Intel or compatible Pentium III 1 GHz or faster processor (2 GHz or faster is recommended)
  • 64-bit systems: Itanium processor or faster. 1 GHz or higher processor
  • Memory: Minimum of 512 MB of RAM (2.048 GB recommended)
  • Storage: At least 2.0 GB of available hard disk space
  • Supported Operating Systems: Windows Server 2008 ; Windows Server 2003 Service Pack 2; Windows Server 2003 Small Business Server R2; Windows Vista; Windows XP Service Pack 2

1. Locate and double-click Setup.exe to begin the installation. The following message will appear on your screen:



2. Click "OK" to proceed to the installation of the prerequisites specified.


3.The next is a welcome screen that shows a license agreement. Select the "I have read and accept the terms of the License Agreement" radio button, and then click the "Install" button.


4. The below screen shows that Setup has started to download software needed to start the installation.


5. Once the Setup program completes the Framework installation, the screen Next will appear on your screen. Click the "Exit" button to complete this stage.


6. The next screen belongs to the wizard used to install the Windows Installer 4.5, required by Microsoft SQL Server 2008. To continue the installation of this update on the "Next" button.


7. On the screen shown below, read the license agreement and if you agree with it, select the "I agree" radio button and click on "Next".


8. If you receive the below screen just click on "Continue".


9. The next page announces that installation of Windows Installer 4.5 has finished and your computer need to be restarted. Click on the "Finish" button to restart your machine.



10. After restarting your computer, run Microsoft SQL Server 2008 setup again. The SQL Server Installation Center screen will show up.


11. On the screen above, make a click on the "Installation" hyperlink in the left side of the screen.


12. The screen shows the types of installation available. Let's select the first type available "New SQL Server stand-alone installation or add features to an existing installation".


13. The next screens belong to the first set of Setup Support Rules.


14. On the page below, specify the edition of SQL Server to install. We chose the Enterprise Evaluation Edition.


15. On the License Terms page. Read the license agreement and if you agree with it, check the "I accept the license terms" check box, and then click the Next button.


16. The next screens belong to the second set of Setup Support Rules.



17. On the Feature Selection page, select the features for your installation.


18. On the Instance Configuration page, select a default or named instance for your installation, and select the directory where you want to install the features you have chosen.


19. The next page is just for the purpose of reviewing disk usage. Click on the "Next" button to continue setup.


20. Microsoft recommends you to specify an individual account for each service. The service accounts used for this configuration must have a strong password, otherwise you will get the error "Invalid or missing username or password. To continue, provide valid credentials for the SQL Server Agent service". A strong password is one that has a combination of letters in uppercase, lowercase, numbers and special characters.


21. For the purpose of this article, we chose to use the same service account for all services, except for the SQL Server Integration Services, thus we click on the "Use the same account for all SQL Server services" button.

22. After the password was provided, we change the account name for SQL Server Integration Services to its default service account, which is the Network Service account.


23. On the Collation tab, specify the collation for your SQL Server instance.

24. On the Database Engine Configuration page, choose the authentication mode to use for your SQL Server installation. If you select Windows Authentication, Setup creates an sa account.



25. Enter and confirm the password for the (sa) login when you choose Mixed Mode Authentication.

26. You will get the error "Missing system administrator account. To continue, provide at least one Windows account to provision ...", if you fail to provide SQL Server administrators and try to continue with the next page of Setup. The error message "There are validation errors on this page ..." will also appear. Click the buttons "AddCurrent User" or "Add ..." to provide at least one account that will have unrestricted access to the SQL Server instance.


27. Now, you can click on "Next".

28. On this page, provide user account that will be Analysis Services administrators.


29. If you selected Reporting Services as a feature to install, the Report Services Configuration page is displayed. Here we chose to install Reporting Services on Native mode.


30. On the Error and Usage Reporting page, optionally clear each check box to disable error reporting.


31. The next screens belong to the Setup Installation Rules.


32. On the Ready to Install page, review the summary of features and components for your SQL Server installation. To proceed, click Install.


33. On the Installation Progress page, you can monitor installation progress as Setup proceeds.


34. Click on the "Next" button, when Setup process complete.


35. Please wait until this dialog disappear.


36. On the Completing the Microsoft SQL Server Installation Wizard page, you can view the Setup summary log by clicking the link provided on this page. To exit the SQL Server Installation Wizard, click Close.


37. Close the SQL Server Installation Center and open the SQL Server Configuration Manager.


38. Enable the appropriate protocols.



39. Restart the MSSQLSERVER service.


Fix problem “The ‘VSTS for Database Professionals Sql Server Data-tier Application’ package did not load correctly”


“The ‘VSTS for Database Professionals Sql Server Data-tier Application’ package did not load correctly”



Visual Studio 2010 and SQL Server Express have an uneasy alliance, at best.  When you install Visual Studio 2010 it installs SQL Server Express 2008 for you, but only the database engine, not SQL Server Management Studio.  If you mess with SQL Server Express in order to install the management tools, or upgrade to 2008 R2, or install the Advanced Services version, things break and you can no longer reliably use the Visual Studio database projects.
In particular, if you remove SQL Server Express 2008 and install SQL Server Express 2008 R2, you’ll probably run into an issue where if you try to open a schema object in a Visual Studio database project you’ll get an error that says:
The ‘VSTS for Database Professionals Sql Server Data-tier Application’ package did not load correctly.
The fix for this problem can be found here.  Here’s the short version:
  1. Locate your Visual Studio 2010 installation media.
  2. In the \WCU\DAC folder, you’ll find three MSIs: DACFramework_enu.msi, DACProjectSystemSetup_enu.msi, and TSqlLanguageService_enu.msi.  Run and install each of them.
  3. Reapply Visual Studio 2010 SP1.
You should be back to a working state.

Wednesday, June 19, 2013

Download Crystal Reports for Visual Studio 2012





By default, Visual Studio doesn’t come with Crystal Reports. Microsoft has now its own reporting tool with an .rdlc extension. In order to use Crystal Reports for Visual Studio, you need to download it from SAP’s website.
Crystal Reports is now called “SAP Crystal Reports, developer version for Microsoft Visual Studio” and can be downloaded at http://scn.sap.com/docs/DOC-35074.
The current version as at the time of this writing is 13.0.5. You may need to visit the link above to get the latest release.



Download Crystal Reports 2010 for Visual Studio Now


Supported Operating Systems

Design Time

The following operating systems shall be supported for design time scenarios (i.e., in development environments).  Each operating system shall be supported in both 32-bit and 64-bit versions (as supported by the operating system).
  • Windows Vista SP2
  • Windows XP SP3 Professional
  • Windows Server 2003 SP2
  • Windows Server 2003 R2
  • Windows 7
  • Windows Server 2008 R2

Runtime

The following operating systems shall be supported for runtime scenarios (i.e., deployment/client environments).  Each operating system shall be supported in both 32-bit and 64-bit versions (as supported by the operating system).
  • Windows Vista SP2
  • Windows XP SP3 Professional
  • Windows Server 2003 SP2
  • Windows Server 2003 R2
  • Windows 7
  • Windows Server 2008 R2

Minimum Hardware Requirements

  • Crystal Reports for Visual Studio is supported running on 32-bit versions of Windows running on x86 and x64 CPUs made by AMD and Intel.
  • Crystal Reports for Visual Studio is supported running on 64-bit versions of Windows running on x64 CPUs made by AMD and Intel.

Design Time

  • 1.6Ghz or faster processor,
  • 1 GB (32 Bit) or 2 GB (64 Bit) RAM ,
  • 650MB (32-bit) or 1.1GB (64-bit) available hard drive space

Runtime

  • Intel Pentium III or faster processor,
  • 512 MB RAM, 
  • 300MB (32-bit) or 325MB (64-bit) available hard drive space
Unfortunately only Visual Studio 2010 is supported. Well, I think it’s not actually a big deal. Since other version like 2008 and below has built-in Crystal Reports.
Download now at share your experience here. You may also wish to share your source code and promote yourself to the programmer’s community.
Happy coding!

Tuesday, June 18, 2013

Convert Number to Roman Numerals in Sql Serve

CREATE FUNCTION fnConvertIntToRoman(@i INT)
RETURNS VARCHAR(100)
AS
BEGIN
    RETURN    Replicate('M', @i/1000)
            + REPLACE(REPLACE(REPLACE(
                  Replicate('C', @i%1000/100),
                  Replicate('C', 9), 'CM'),
                  Replicate('C', 5), 'D'),
                  Replicate('C', 4), 'CD')
             + REPLACE(REPLACE(REPLACE(
                  Replicate('X', @i%100 / 10),
                  Replicate('X', 9),'XC'),
                  Replicate('X', 5), 'L'),
                  Replicate('X', 4), 'XL')
             + REPLACE(REPLACE(REPLACE(
                  Replicate('I', @i%10),
                  Replicate('I', 9),'IX'),
                  Replicate('I', 5), 'V'),
                  Replicate('I', 4),'IV')

END

How to recover corrupted database file( .mdf .ldf).

EXEC sp_configure 'allow updates',1

RECONFIGURE WITH OVERRIDE

UPDATE sysdatabases SET status=1073741840 WHRE name='DatabaseName'

CHECKPOINT--shutdown with nowait

DBCC traceon(3604)

DBCC rebuild_log ('DatabaseName', 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\DatabaseName_Log.LDF')


USE DatabaseName
sp_dboption 'DatabaseName', 'single_user', 'true'

ALTER DATABASE DatabaseName SET SINGLE_USER WITH ROLLBACK IMMEDIATE

DBCC CHECKDB (DatabaseName, REPAIR_ALLOW_DATA_LOSS) WITH NO_INFOMSGS

USE MASTER

UPDATE sysdatabases SET status = 0 WHERE name = 'DatabaseName'

DBCC CHECKALLOC ('DatabaseName')

DBCC CHECKDB ('DatabaseName')

sp_dboption 'DatabaseName', 'single_user', 'false'

USE MASTER

sp_configure 'allow updates', 0

EXEC sp_resetstatus DatabaseName 

Wednesday, June 5, 2013

Windows application for converting Text into Speech.

Hi Friends, in this post I would like to explain how to convert Text into Speech.



· Open windows application.
· Place a TextBox & a Button control on to the form.
· Goto ProjectMenu---> Add Reference---> COM---> MicrosoftSpeechObjectLibrary (Add this reference).
· Add the following namespace: using SpeechLib;
Please go through the code under button click event:



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SpeechLib;


namespace TextToSpeech
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}


private void btnClick_Click(object sender, EventArgs e)
{
SpVoice voice = new SpVoice();//Where SpVoice is the Speakers Voice.
voice.Speak(textBox1.Text,SpeechVoiceSpeakFlags.SVSFDefault);
}
}
}






Thank You...

Introduction to Windows Services.



Hi friends,in this post i would like to explain some basic things to know about windows services.





* A service which is under control of windows OS is called windows service.
* Windows services are used to develop automated background processes.
* Windows services contains only application logic but not GUI(Graphical User Interface).
* The controls which are not visible at runtime,can be placed in windows service projects.





For example:
Timer Control,Event log control,File system watcher control.





* To develop windows services .Net provided:
File-->NewProject-->VisualC#-->Windows-->WindowsServiceTemplate.
* Windows service project is avilable in VisualStudio .Net 2005 professional edition,but not available in Standard edition.
* To develop windows service .Net provided a name space:
System.ServiceProcess(NameSpace).
* All the windows services will be stored at:
Start-->Settings-->ControlPanel-->AdministrativeTools-->Services
OR
Start-->run-->Services.msc
* While a service is starting OnStart() event will be executed & while stoping OnStop() event will be executed.





Steps for developing Windows Service:






1)Open windows service project & wrie the required logic.
2)Add the installers & build the project to get an exe file as output.
3)Open .Net command prompt & install exefile with following syntax:
installutil -i exefile path //for installing the service.
installutil -u exefile path //for uninstalling the service.
4)Start the service.







Thank you...

Example on Windows Service



Hi Friends,in this post i would like to explain windows service for displaying message box for every 3 seconds.

Step 1:

* Open windows service project with projectName WinService1
* Goto ToolBox-->General-->Right Click-->Select choose items-->Select Timer(Systems.Timers)
* Project-->AddReference-->System.Windows.Forms(Message Box is a part of above reference).
* Place a Timer(System.Timers) with interval-3000 & enabled-false.

Code:

{//timer1_Elapsed event.
System.Windows.Forms.MessageBox.Show("This message from Windows Service.");
}

Code for OnStart() event
{
timer1.Enabled=true;
}

Code for OnStop() event
{
timer1.Enabled=false;
}





Step 2:

* Open service1.cs[design]
Right Click
Add installer(Select).
Then 2 controls will be added to the form.
1)ServiceProcessInstaller-->Choose properties-->Account=LocalSystem.
2)ServiceInstaller-->Properties-->ServiceName=MessageBoxDisplay

* Build the project(Build-->Select Build solution)

Note:
* WinService1.exe is created under:
D:\WinService1\bin\debug folder with a service name called as "MessageBoxDisplay"

Step 3:

* open .Net Command prompt.
Start-->Programs-->MSVisualStudio2005-->VSTools-->.Net Command Prompt.
>installutil -i D:\WinService1\bin\debug\WinService1.exe (press enter)
>....
>....
>....
>transaction install has completed.

Step 4:

* Open service(Start-->run-->services.msc)
* MessageBoxDisplay-->RightClick-->Properties-->Logon-->Check "interact with desktop" checkBox-->OK
(Only service contains MessageBox otherwise above step is not required).
* MessageBoxDisplay-->rightClick-->Start.

Then service will be started & MessageBox with message(This message from Windows Service.) will be displayed for every 3 seconds.


Thank You...

Displaying Festival Names on Calendar control in ASP.Net

Hi Friends,In this article i would like to explain how to display Festival Names on Calender control in ASP.Net.

* For this i took 1 Calendar control on to the page.

* I created a table with name(Holidays) in SQL Server 2005 & fields are HolidayName,HolidayDate.

* Please find the below table once :


* Then find the code for Calender_DayRender event : 
Source Code : 

Default.aspx.cs :

    using System;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.Data.SqlClient;
    public partial class _Default : System.Web.UI.Page
    {
    SqlConnection con;
    protected void Page_Load(object sender, EventArgs e)
    {
     con = new SqlConnection(ConfigurationManager.ConnectionStrings["DotnetGuruConnectionString"].ConnectionString);
    }
    protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
    {
     CalendarDay day = (CalendarDay)e.Day;
     SqlCommand cmd = new SqlCommand("select HolidayName,HolidayDate from Holidays", con);
     con.Open();
     SqlDataReader dr = cmd.ExecuteReader();

     while (dr.Read())
     {
         if (day.Date.ToString() == dr["HolidayDate"].ToString())
         {
             TableCell cell = (TableCell)e.Cell;
             string s1 = dr["HolidayName"].ToString();
             if (s1 != null)
             {
                 cell.BackColor = System.Drawing.Color.LightGray;
                 cell.Controls.Add(new LiteralControl("
    " + s1));
             }

         }

     }
     con.Close();
    }
    }

Design View : 

Default.aspx :

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
SqlConnection con;
protected void Page_Load(object sender, EventArgs e)
{
 con = new SqlConnection(ConfigurationManager.ConnectionStrings["DotnetGuruConnectionString"].ConnectionString);
}
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
 CalendarDay day = (CalendarDay)e.Day;
 SqlCommand cmd = new SqlCommand("select HolidayName,HolidayDate from Holidays", con);
 con.Open();
 SqlDataReader dr = cmd.ExecuteReader();

 while (dr.Read())
 {
     if (day.Date.ToString() == dr["HolidayDate"].ToString())
     {
         TableCell cell = (TableCell)e.Cell;
         string s1 = dr["HolidayName"].ToString();
         if (s1 != null)
         {
             cell.BackColor = System.Drawing.Color.LightGray;
             cell.Controls.Add(new LiteralControl("
" + s1));
         }

     }

 }
 con.Close();
}
}


* Then finally Build(F6) your application & run the application by pressing(F5) button.

* Your out put will looks like as below : 
Thank You...