Here a piece of #C code, I use to create session for NHibernate:
1. Configuration config = new Configuration();
2. config.Configure();
3. ISessionFactory factory = config.BuildSessionFactory();
4.......
Line 3 would raise error something like "Could not create the driver from NHibernate.Driver.MySqlDataDriver"
I pointed to Mysql.Data.dll file in References folder on the Solution Exploreror, than change Copy Global property from false to true. The code could work to open a session.
Kamis, 23 September 2010
Selasa, 21 September 2010
Vista Batch File and Command Prompt
I have a problem to edit .bat file on Vista, but can run by double-clicking on it.
An error message appears when trying to edit the file through Windows Explorer.
I downloaded .zip file from here, then unzipped. Right-click on batfix_vista.REG file then select Merge will fix batch file association.
Right-click to edit with Notepad and double-click to run, work as expected. Here a list of file associations for Vista.
One more...sometimes, we want to display a command prompt in accordance with the location of the folder from Windows Explorer. For this purpose press the SHIFT key + right-click then select Open Command Window Here.
An error message appears when trying to edit the file through Windows Explorer.
I downloaded .zip file from here, then unzipped. Right-click on batfix_vista.REG file then select Merge will fix batch file association.
Right-click to edit with Notepad and double-click to run, work as expected. Here a list of file associations for Vista.
One more...sometimes, we want to display a command prompt in accordance with the location of the folder from Windows Explorer. For this purpose press the SHIFT key + right-click then select Open Command Window Here.
Minggu, 12 September 2010
A generic error occurred in GDI+ and The process cannot access the file...
I have a database that stores data on a server and use directory as a placeholder for .jpg files. In this application, I store images in folders instead of using BLOB data type, so there is a correspondence between each record with image files, and also there are references to several fields with their corresponding image file.
When viewing the data in the DataGridView, images should be shown in Picture Box, using this function.
If a user wants to link an image with a record, he chose the image file first and then clicking the save button.
The following function will save the bitmap image that is displayed in the Picture Box as an image file in the directory of the server.
Make changing of the image, will raise an error The process cannot access the file '\\10.11.12.13\\f128.jpg' because it is being used by another process.
It occurs when use fotobox.Image = System.Drawing.Image.FromFile(fname); line number 10 of NextPrevRow()function, and these commands in SaveImageToFile() function:
If I remark commands to delete files, and leave Save command only in SaveImageToFile() function, an error thrown: A generic error occurred in GDI+.
I modify the commands, error messages about file locking does not exist anymore.
When viewing the data in the DataGridView, images should be shown in Picture Box, using this function.
private void NextPrevRow()
{
DataRowView drv = (DataRowView)bindSrc0.Current;
if (drv == null) return;
string fname = myGlobVar.UNC + "\\f"+drv["pk"].ToString().Trim()+".jpg";
if (System.IO.File.Exists(fname))
{
try
{
fotobox.Image = System.Drawing.Image.FromFile(fname);
}
catch { }
}
else
fotobox.Image = null;
}
If a user wants to link an image with a record, he chose the image file first and then clicking the save button.
The following function will save the bitmap image that is displayed in the Picture Box as an image file in the directory of the server.
private void SaveImageToFile()
{
DataRowView drv = (DataRowView)bindSrc0.Current;
if (fotobox.Image != null)
{
string fname = myGlobVar.UNC + "\\f" + drv["pk"].ToString().Trim() + ".jpg";
try
{
if (File.Exists(fname))
File.Delete(fname);
fotobox.Image.Save(fname, ImageFormat.Jpeg);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
Make changing of the image, will raise an error The process cannot access the file '\\10.11.12.13\\f128.jpg' because it is being used by another process.
It occurs when use fotobox.Image = System.Drawing.Image.FromFile(fname); line number 10 of NextPrevRow()function, and these commands in SaveImageToFile() function:
if (File.Exists(fname))
File.Delete(fname);
fotobox.Image.Save(fname, ImageFormat.Jpeg);
If I remark commands to delete files, and leave Save command only in SaveImageToFile() function, an error thrown: A generic error occurred in GDI+.
I modify the commands, error messages about file locking does not exist anymore.
private void NextPrevRow()
{
DataRowView drv = (DataRowView)bindSrc0.Current;
if (drv == null) return;
string fname = myGlobVar.UNC + "\\f"+drv["pk"].ToString().Trim()+".jpg";
if (System.IO.File.Exists(fname))
{
try
{
FileStream fs = File.OpenRead(fname);
byte[] data = new byte[fs.Length];
fs.Read(data, 0, data.Length);
fs.Close();
MemoryStream ms = new MemoryStream(data);
Bitmap bmp = new Bitmap(ms);
fotobox.Image = bmp;
ms.Close();
}
catch { }
}
else
fotobox.Image = null;
}
private void SaveImageToFile()
{
DataRowView drv = (DataRowView)bindSrc0.Current;
if (fotobox.Image != null)
{
string fname = myGlobVar.UNC + "\\f" + drv["pk"].ToString().Trim() + ".jpg";
try
{
// if (File.Exists(fname))
// File.Delete(fname);
fotobox.Image.Save(fname, ImageFormat.Jpeg);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
Selasa, 07 September 2010
Could not load file or assembly 'System.Core, Version=3.5.0.0..'
After installing the application on the client, I try to open forms and they are working correctly. But for some other forms, an error message appears
Could not load file or assembly 'System.Core, Version = 3.5.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089' or one of its dependencies. " The system cannot find the file specified.
I click the details button to find the cause of the error, then check the appropriate source code line number as reported. Although the code works correctly on the development machine, I'm trying to find out why the problem appears on the line, I then realized that I am using LINQ and version of the .NET Framework on the client computer suspected as the cause of the problem.
I finally arrived at here and here. After upgrading to. NET Framework 3.5, the application run correctly.
Just picture it, .NET Framework 3.5 features include the following:
Could not load file or assembly 'System.Core, Version = 3.5.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089' or one of its dependencies. " The system cannot find the file specified.
I click the details button to find the cause of the error, then check the appropriate source code line number as reported. Although the code works correctly on the development machine, I'm trying to find out why the problem appears on the line, I then realized that I am using LINQ and version of the .NET Framework on the client computer suspected as the cause of the problem.
I finally arrived at here and here. After upgrading to. NET Framework 3.5, the application run correctly.
Just picture it, .NET Framework 3.5 features include the following:
- Deep integration of Language Integrated Query (LINQ) and data awareness. This new feature will let us write code written in LINQ-enabled languages to filter, enumerate, and create projections of several types of SQL data, collections, XML, and DataSets by using the same syntax.
- ASP.NET AJAX lets you create more efficient, more interactive, and highly-personalized Web experiences that work across all the most popular browsers.
- New Web protocol support for building WCF services including AJAX, JSON, REST, POX, RSS, ATOM, and several new WS-* standards.
- Full tooling support in Visual Studio 2008 for feature sets in Windows Workflow Foundation (WF), Windows Communication Foundation (WCF), Windows Presentation Foundation (WPF) and Windows CardSpace, including the new workflow-enabled services technology.
- New classes in .NET Framework 3.5 base class library (BCL) that address many common customer requests.
System Requirements:
- Supported Operating Systems: Windows Server 2003; Windows Server 2008; Windows Vista; Windows XP
- Processor: 400 MHz Pentium processor or equivalent (Minimum); 1GHz Pentium processor or equivalent (Recommended)
- RAM:96 MB (Minimum); 256 MB (Recommended)
- Hard Disk: Up to 500 MB of available space may be required
Specify .NET Framework Target for a Project
We specify a specific .NET Framework target while creating a new project or change it later. For a new project, i.e after a New Project dialog box appear (by clicking Project on the File menu, New Project), we select the .NET Framework version we want from a drop down list.
To change a .NET Framework version:
1. Locate the Project Designer, by right click on a project in the Solution Explorer, then click Properties.
2a. For C#, on the Application tab, locate Target Framework and select .NET Framework version.
2b. For VB, click Compile tab on the Project Designer then click Advanced Compile Options.. from drop down list to choose .NET Framework version.
To change a .NET Framework version:
1. Locate the Project Designer, by right click on a project in the Solution Explorer, then click Properties.
2a. For C#, on the Application tab, locate Target Framework and select .NET Framework version.
2b. For VB, click Compile tab on the Project Designer then click Advanced Compile Options.. from drop down list to choose .NET Framework version.
Selasa, 10 Agustus 2010
Create PDF file using C# and iTextSharp
iText is a library that allows you to generate PDF files on the fly, and it is an ideal library for developers looking to enhance web- and other applications with dynamic PDF document generation and/or manipulation. iText is not an end-user tool. Typically you won't use it on your Desktop as you would use Acrobat or any other PDF application. Rather, you'll build iText into your own applications so that you can automate the PDF creation and manipulation process.
The iText classes are very useful for people who need to generate read-only, platform independent documents containing text, lists, tables and images; or who want to perform specific manipulations on existing PDF documents.
Say we already have a C# project created with Microsoft Visual Studio, and want to generate a PDF file using iTextSharp. Below is my step:
1. Download itextsharp-5.0.2-dll.zip (1.2MB) from http://sourceforge.net/projects/itextsharp/files/
2. Extract the zip file to get itextsharp.dll file.
3. On Visual Studio, Add Reference to that file.
4. Open your source code and put this
using iTextSharp.text;
using iTextSharp.text.pdf;
5. Create a function like this:
private void generatePDF()
{
Document doc = new Document();
string dirPath = AppDomain.CurrentDomain.BaseDirectory + "pdf";
string pdfFile = dirPath + "\\" + "my.pdf";
PdfWriter writer = PdfWriter.GetInstance(doc, new System.IO.FileStream(pdfFile, System.IO.FileMode.Create));
writer.SetEncryption(PdfWriter.STRENGTH128BITS, "readpassw", "editpassw", PdfWriter.AllowCopy PdfWriter.AllowPrinting);
doc.Open();
doc.AddTitle("iTextSharp");
doc.AddSubject("Create Paragraph");
doc.AddCreator("iTextSharp");
doc.AddAuthor("We");
doc.AddTitle("My Title");
string tit = "This document using 128 bits encryption";
doc.Add(new Paragraph(tit, FontFactory.GetFont(FontFactory.HELVETICA, 20, 5,BaseColor.BLUE)));
Paragraph p = new Paragraph(new Chunk("iText is a library that allows you to generate PDF files on the fly", FontFactory.GetFont(FontFactory.HELVETICA, 10)));
p.Add("The most recent version is iText 5.0.3.");
p.Add("iText is an ideal library for developers looking to enhance web-");
p.Add(new Chunk("and other applications with dynamic PDF document generation and/or manipulation."));
p.Add(new Phrase("iText is not an end-user tool."));
p.Add(new Phrase("You'll build iText into your own applications to automate the PDF creation and manipulation process.", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 18)));
doc.Add(p);
doc.NewPage();
p = new Paragraph(new Phrase("This is my second paragraph.", FontFactory.GetFont(FontFactory.TIMES_ITALIC, 11)));
p.Add("In short: the iText classes are very useful for people who need.");
doc.Add(p);
doc.Close();
}
6. Call that function and chek my.pdf file using your PDF reader.
The iText classes are very useful for people who need to generate read-only, platform independent documents containing text, lists, tables and images; or who want to perform specific manipulations on existing PDF documents.
Say we already have a C# project created with Microsoft Visual Studio, and want to generate a PDF file using iTextSharp. Below is my step:
1. Download itextsharp-5.0.2-dll.zip (1.2MB) from http://sourceforge.net/projects/itextsharp/files/
2. Extract the zip file to get itextsharp.dll file.
3. On Visual Studio, Add Reference to that file.
4. Open your source code and put this
using iTextSharp.text;
using iTextSharp.text.pdf;
5. Create a function like this:
private void generatePDF()
{
Document doc = new Document();
string dirPath = AppDomain.CurrentDomain.BaseDirectory + "pdf";
string pdfFile = dirPath + "\\" + "my.pdf";
PdfWriter writer = PdfWriter.GetInstance(doc, new System.IO.FileStream(pdfFile, System.IO.FileMode.Create));
writer.SetEncryption(PdfWriter.STRENGTH128BITS, "readpassw", "editpassw", PdfWriter.AllowCopy PdfWriter.AllowPrinting);
doc.Open();
doc.AddTitle("iTextSharp");
doc.AddSubject("Create Paragraph");
doc.AddCreator("iTextSharp");
doc.AddAuthor("We");
doc.AddTitle("My Title");
string tit = "This document using 128 bits encryption";
doc.Add(new Paragraph(tit, FontFactory.GetFont(FontFactory.HELVETICA, 20, 5,BaseColor.BLUE)));
Paragraph p = new Paragraph(new Chunk("iText is a library that allows you to generate PDF files on the fly", FontFactory.GetFont(FontFactory.HELVETICA, 10)));
p.Add("The most recent version is iText 5.0.3.");
p.Add("iText is an ideal library for developers looking to enhance web-");
p.Add(new Chunk("and other applications with dynamic PDF document generation and/or manipulation."));
p.Add(new Phrase("iText is not an end-user tool."));
p.Add(new Phrase("You'll build iText into your own applications to automate the PDF creation and manipulation process.", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 18)));
doc.Add(p);
doc.NewPage();
p = new Paragraph(new Phrase("This is my second paragraph.", FontFactory.GetFont(FontFactory.TIMES_ITALIC, 11)));
p.Add("In short: the iText classes are very useful for people who need.");
doc.Add(p);
doc.Close();
}
6. Call that function and chek my.pdf file using your PDF reader.
Sabtu, 07 Agustus 2010
Boot on Ring
Seminggu yang lalu, saya berada sekitar 1000 km dari server sebut saja "DearServer". Perjalanan yang mengasyikkan bersama Hari, Suhendra, Teguh. Canda tawa, guyonan dan ide "andai-andai" pun mewarnai perjalanan kami saat melihat indahnya pemandangan, orang, mesin, makanan, bahkan sensor di bandara...bak komentator..dengan rileks dan tanpa beban menyampaikan pandangannya...
Kami beranjak meninggalkan DearServer pukul 05.40 dan tiba di remote area sekitar jam 16. Jam 20 memulai setup komputer, camera, cabling, konfigurasi LAN, tes koneksi internal dan ke internet via RG. Semua lancar dan response aplikasinya baik. Oh ya di DearServer ada rekan Salihin, yang setia menssuport kami, dan di server lokal ada rekan Iwan yang mendampingi. Dari testing aplikasi App2 kami masih menemui kendala. Jam telah menunjukkan hampir pukul 23 dan kami pun istirahat.
Esoknya kami mulai pelatihan internal dan laptop Vaio18 pun digunakan hingga jam 16. Jam 21, PR untuk App2 dilanjutkan. Untuk misi kali ini, ada 2 Aplikasi di DearServer yang harus dijalankan. App1 dan App2.
App1 terbuka untuk diakses via internet, sedangkan App2 khusus untuk intranet. App1 bisa diakses, namun tidak untuk App2. Koneksi VPN digunakan namun gagal koneksi ke App2. Routing dinamik dibuat dan App2 bisa diakses. Naah, sekarang saatnya mengganti dengan routing statis.
Saat membuat routing statis saya membuat IP yang sama (konflik) dalam server island, SSH pun terputus. Jam telah menunjukkan pukul 23, tak mungkin menelpon Salihin untuk datang mereset DearServer. Ide pun muncul andai bisa menelpon petugas untuk melakukan warm/cold boot server, andai ada tambahan NIC, atau andai ring telepon yang membuat Boot On Ring...next time kali yaaa.. Hmmmm...routing statis kan bisa dikerjakan besok pagi...kami melakukan finishing dan kembali pukul 01.
Kicau burung di pagi hari pun terdengar, suasana yang langka saat berada di kotanya DearServer, saat jalan pagi dan melihat pohon dan gunung yang masih tertutup embun...amazing deh...sementara Teguh menelpon Salihin untuk merestart DearServer. Jam 09, routing diberesin, dan semua OK..pada saat yang tepat... Sesuai jadwal, pelatihan eksternal pun dibuka oleh pak Edy dan kami melanjutkan dengan materi dan praktek pelatihan. Hal yang menyenangkan diperoleh dengan tidak adanya gangguan koneksi maupun hambatan pengoperasian aplikasi. Mission completed...dan perjalanan panjang menanti untuk eksekusi real-world.
Kami beranjak meninggalkan DearServer pukul 05.40 dan tiba di remote area sekitar jam 16. Jam 20 memulai setup komputer, camera, cabling, konfigurasi LAN, tes koneksi internal dan ke internet via RG. Semua lancar dan response aplikasinya baik. Oh ya di DearServer ada rekan Salihin, yang setia menssuport kami, dan di server lokal ada rekan Iwan yang mendampingi. Dari testing aplikasi App2 kami masih menemui kendala. Jam telah menunjukkan hampir pukul 23 dan kami pun istirahat.
Esoknya kami mulai pelatihan internal dan laptop Vaio18 pun digunakan hingga jam 16. Jam 21, PR untuk App2 dilanjutkan. Untuk misi kali ini, ada 2 Aplikasi di DearServer yang harus dijalankan. App1 dan App2.
App1 terbuka untuk diakses via internet, sedangkan App2 khusus untuk intranet. App1 bisa diakses, namun tidak untuk App2. Koneksi VPN digunakan namun gagal koneksi ke App2. Routing dinamik dibuat dan App2 bisa diakses. Naah, sekarang saatnya mengganti dengan routing statis.
Saat membuat routing statis saya membuat IP yang sama (konflik) dalam server island, SSH pun terputus. Jam telah menunjukkan pukul 23, tak mungkin menelpon Salihin untuk datang mereset DearServer. Ide pun muncul andai bisa menelpon petugas untuk melakukan warm/cold boot server, andai ada tambahan NIC, atau andai ring telepon yang membuat Boot On Ring...next time kali yaaa.. Hmmmm...routing statis kan bisa dikerjakan besok pagi...kami melakukan finishing dan kembali pukul 01.
Kicau burung di pagi hari pun terdengar, suasana yang langka saat berada di kotanya DearServer, saat jalan pagi dan melihat pohon dan gunung yang masih tertutup embun...amazing deh...sementara Teguh menelpon Salihin untuk merestart DearServer. Jam 09, routing diberesin, dan semua OK..pada saat yang tepat... Sesuai jadwal, pelatihan eksternal pun dibuka oleh pak Edy dan kami melanjutkan dengan materi dan praktek pelatihan. Hal yang menyenangkan diperoleh dengan tidak adanya gangguan koneksi maupun hambatan pengoperasian aplikasi. Mission completed...dan perjalanan panjang menanti untuk eksekusi real-world.
Langganan:
Postingan (Atom)