Pages

Search This Blog

Showing posts with label visual studio 2005. Show all posts
Showing posts with label visual studio 2005. Show all posts

Monday, August 22, 2011

ASP.NET - new session id when refresh the page

Using Visual Studio 2005, dotnet framework 2.0.

Try to get a session id in default.aspx


  public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            txtSessionID.Text = this.Session.SessionID;
        }
    }

when i refresh the page, new session id show. This is weird because it won't happen in Asp.net for dotnet framework 1.1.

To solve the problem, simply add below code in global.asax to register an event handler for the session start event


void Session_Start(Object sender, EventArgs e)
        {

        }


Thursday, December 17, 2009

Failed to create the Crystal Query Engine Visual Studio 2005

When try to open crystal report in VS 2005, error message appear "Failed to open document" and followed by message "Failed to create the Crystal Query Engine".

I believe it same case with what discuss in http://social.msdn.microsoft.com/Forums/en/vscrystalreports/thread/79e1da80-f5c6-42fa-80ca-65a10de5729d .

The root cause maybe because of installation and uninstallation of merge module. Many recommend that we remove the crystal report, after that add crystal report back to visual studio. Steps below

  1. Go to Add/Remove Programs and select Change/Remove for Microsoft Visual Studio 2005
  2. Select Next then Add or Remove Features from the Visual Studio 2005 Maintenance Mode app
  3. Uncheck Crystal Reports for Visual Studio and select Update
  4. Once the "Update" is complete, select Finish
  5. Go back to Add/Remove Programs and select Change/Remove for Microsoft Visual Studio 2005
  6. Select Next then Add or Remove Features from the Visual Studio 2005 Maintenance Mode app
  7. Check Crystal Reports for Visual Studio and select Update
  8. Insert Disk 1 of Microsoft Visual Studio 2005 Installation CD's and select OK
  9. Once the "Update" is complete, select Finish

But in my case, i don't have installation CDs with me. So, i try an alternative way to get it work. You can try it but at your own risk.

I have another development machine which i call it machine B which have VS 2005 with crystal report install and working fine. The one have problem, i call it machine A. What i do is:

1. go to machine B, go to folder C:\Program Files\Common Files\Business Objects\2.7
2. copy the whole bin folder to a external drive or pendrive or thumb drive
3. close the visual studio 2005 in machine A if it's open
4. go to machine A, go to folder C:\Program Files\Common Files\Business Objects\2.7 and rename the bin folder to binA for backup purposes
5. copy the bin for the external drive to C:\Program Files\Common Files\Business Objects\2.7 in machine A
6. try to open visual studio 2005 and open the crystal report development file.
7. it working

It solve my problem especially when i don't have the installation cds with me at the moment. Hope this help

Friday, March 13, 2009

Resize Image in Crystal Report 9 Visual Studio 2005

Well, many may think or looking for resize image in Crystal Report 9. Here is some hints and code that may help. Hopefully you can understand after go thru simple sample code.

1 pixel should be equal to 15 twips in Crystal Report.

int LogoWidth = 100;

      int LogoHeight = 80;

reportdocument.Load("abc.rpt");

reportdocument.SetDataSource(myDataTable);

reportdocument.Section2.ReportObjects["LogoImage1"].Width = LogoWidth * 15;

reportdocument.Section2.ReportObjects["LogoImage1"].Height = LogoHeight * 15;

CrystalReportViewer.ReportSource = reportdocument;

Sunday, February 15, 2009

Develop application using SQL Compact 3.5 SP1 with Visual Studio 2005

Can MS SQL Compact 3.5 SP1 work together with VS 2005? The answer is yes.

We are using Visual Studio 2005 (C#) and wish to create a window desktop application. After some consideration, the decision is for for MS SQL Compact 3.5 SP1. 

To enable me to work on MS SQL Compact 3.5 SP1:
  • Install MS SQL Compact 3.5 SP1 
  • Install MS SQL 2008 Express - to get SQL Server Management Studio to work with SQL Compact for table creation and scripting.
  • Add MS SQL Compact 3.5 SP1 engine to VS 2005 project
  • Connect to MS SQL Compact 3.5 SP1 engine in VS 2005 (C#) project

Install MS SQL Compact 3.5 SP1


The installation is easy and straightforward. I assume there will be no problem facing here.


Install MS SQL 2008 Express - to get SQL Server Management Studio to work with SQL Compact for table creation and scripting

In order to install MS SQL 2008 Express, you need to have below installed prio to that
  • Microsoft .NET Framework 3.5 Service Pack 1
  • Windows Installer 4.5
  • Windows PowerShell 1.0

After finish installation, you can connect to the MS SQL Compact 3.5 SP1 using SSMS. Open SSMS, choose Server type: "SQL Server Compact Edition" as shown below.


After that you can choose to create a new MS SQL Compact database or use the existing one as shown below:


After the connection, you can create table and etc. 

p/s: if you hit error "'' is not a valid login or you do not have permission" during installation, please refer to my previous post.


Add MS SQL Compact 3.5 SP1 engine to VS 2005 project

Open the project for the application, right click on Reference.



Browse on SQL Server Compact 3.5 sp1 engine (System.Data.SqlServerCe.dll) and add as reference. 

My location is in "C:\Program Files\Microsoft SQL Server Compact Edition\v3.5\Desktop\System.Data.SqlServerCe.dll"

Connect to MS SQL Compact 3.5 SP1 engine in VS 2005 (C#) project

remember to add reference to your C# code

using System.Data;
using System.Data.SqlServerCe;  // <-- Add this

SqlCeConnection _connection;

string fileName = "mycompactDB.sdf";
           string password = "AbCd1@3$5^7*";

           string connectionString = string.Format(
               "DataSource=\"{0}\"; Password='{1}'", fileName, password);

           _connection = new SqlCeConnection(connectionString);
           _connection.Open();

DONE! Hope this can help.

For other reading, can refer to 

SQL Server Compact 3.5
http://technet.microsoft.com/en-us/sqlserver/bb671088.aspx

SQL Server Compact 3.5 How-to Tutorials
http://msdn.microsoft.com/en-us/sqlserver/bb895908.aspx 


SQLCE 3.5 Database Tutorial
http://dotnetperls.com/Content/SQLCE-Database-Use.aspx

Dynamic Image in Crystal Report 9 Visual Studio 2005 - C#

I found many developers facing the same problem as i do - dynamic include image to crystal report with Visual Studio 2005 . This is how we solve our problem in C# when developing a desktop window application.

  1. In your xsd, create a colomn that does not exist in your dataset, example, [LogoImage], and set the datatype to “System.Byte[]”. You might find the datatype option only have “System.Byte”, you can manually type in “[]”.
  2. Add the following code in your form.

    private void AddImageColumn(DataTable objDataTable, string strFieldName)
    {
    try
    {
    DataColumn objDataColumn = new DataColumn(strFieldName,
    Type.GetType("System.Byte[]"));
    objDataTable.Columns.Add(objDataColumn);
    }
    catch (Exception ex)
    {
    //handler
    }
    }

    private void LoadImage(DataRow objDataRow, string strImageField, string FilePath)
    {
    try
    {
    FileStream fs = new FileStream(FilePath, System.IO.FileMode.Open,
    System.IO.FileAccess.Read);
    byte[] Image = new byte[fs.Length];
    fs.Read(Image, 0, Convert.ToInt32(fs.Length));
    fs.Close();
    objDataRow[strImageField] = Image;
    }
    catch (Exception ex)
    {
    //Handler
    }
    }

  3. After your getting your dataset from database and before bind to the report view, do this.

    AddImageColumn(myDataTable, "LogoImage");

    for (int index = 0; index < myDataTable.Rows.Count; index++)
    {
    if (myDataTable.Rows[index]["LogoLocation"].ToString() != "")
    {
    if(File.Exists(myDataTable.Rows[index]["LogoLocation"].ToString()))
    {
    LoadImage(myDataTable.Rows[index], "LogoImage",
    myDataTable.Rows[index]["LogoLocation"].ToString());
    }
    else
    {
    LoadImage(myDataTable.Rows[index], "LogoImage",
    "C:\\NoImage.jpg");
    }
    }
    else
    {
    LoadImage(myDataTable.Rows[index], "LogoImage", "C:\\NoImage.jpg");
    }
    }

  4. Then in your Crystal Report, just drag this column into the report.

Hope this solve your problem.

Saturday, January 31, 2009

Visual Studio 2005 Crystal Reports deployment

Well, we have a visual studio 2005 windows application with crystal report and wish to deploy to customer machine. There are some basic files that needed to deploy to a normal xp home machine:
  • .NET Framework 2.0 - download from microsoft site
  • Project files - compile from Visual Studio 2005
  • Crystal reports merge module - discuss here

Here we will discuss how to create crystal reports merge module setup for deployment purposes.

Below are the steps :
  1. Generate a setup using setup wizard (either create a new project or add a new project to existing project), name it setup1.


  2. Right click in Setup1, select Add-> Merge Module. and open files listed below (by default, it will go to the correct directory which is C:\Program Files\Common Files\Merge Modules).


    Crystal_Database_Access2003.msm
    Crystal_Database_Access2003_enu.msm
    Crystal_Managed2003.msm
    Crystal_regwiz2003.msm



  3. now right click on Crystal_regwiz2003.msm , Click Properties. in properties window, Click on (MergeModuleProperties), in License Key property set license code of crystal report.

    This code can be obtained from Help menu -> About Microsoft Visual Studio, here u find a licence code for 'Crystal Reports'. copy this code and paste it in license key proparty.

  4. Almost done. Now build setup by Right click on Setup1 and Click on Build


  5. Copy the setup1.exe from you project output folder (normally is in Project's Debug or Release folder)

Install this exe during deployment. Done

More reference:

http://msdn.microsoft.com/en-us/library/ms225227(VS.80).aspx
http://msdn.microsoft.com/en-us/library/aa287924(VS.71).aspx
http://msdn.microsoft.com/en-us/library/aa288179(VS.71).aspx
http://msdn.microsoft.com/en-us/library/ms227409(VS.80).aspx


http://resources.businessobjects.com/support/additional_downloads/runtime.asp