Thursday, August 4, 2016

Unexpected Error occurred in the Oracle Data Provider for .NET

While working with Oracle Data Provider with Visual studio you can get the following error:

The description for Event ID 0 from source devenv cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.
If the event originated on another computer, the display information had to be saved with the event.
The following information was included with the event:
An unexpected error occurred in the Oracle Data Provider for .NET.  The data provider 'Oracle Data Provider for .NET' failed to load.  The {18147ff9-1f37-4425-865b-5066a33701de} service could not be found.
the message resource is present but the message is not found in the string/message table


Solution:


The simple solution to this problem is to check your "Server Explorer" in Visual Studio, remove all connections, and then restart Visual studio.

Hopefully your problem will be solved.

Thursday, April 7, 2016

iREPORT (Jasper Reports): Working with date and time

Date and time handling is slightly complex in all Programming Languages, since each area has different date/time format and each language has its own way of handling these objects. In iReport, many developers finds difficulty in formatting, treating date and time in day-to-day operations. I am listing here some of the useful tricks/methods to be used in iReport:


1. To get the current date and time:


new Date()


2. To get the current date only (Today in .Net):


 new Date( (new Date()).getYear(),(new Date()).getMonth(), (new Date()).getDate())


3. To check if a variable / date is null?:


$F{ThisDate} == null


4. In development, there arise some situations in which we have to use the current date if a date is null, then use a variable and assign it the following expression:


$F{ThisDate} == null ? new Date( (new Date()).getYear(),(new Date()).getMonth(), (new Date()).getDate()): $F{ThisDate}

5. To get the difference between two dates (including start and end date) in "No. of Days" unit:


(int) ((($F{OutTime}==null? (new Date( (new Date()).getYear(),(new Date()).getMonth(), (new Date()).getDate())).getTime(): (new Date($F{OutTime}.getYear(),$F{OutTime}.getMonth(), $F{OutTime}.getDate()).getTime())) - (new Date($F{InTime}.getYear(),$F{InTime}.getMonth(), $F{InTime}.getDate())).getTime())/ (1000 * 60 * 60 * 24))+1

where, getTime translates the date into milliseconds which allows to add subtract days.
To convert the result from milliseconds to days we divide the result by  (1000 * 60 * 60 * 24).
To include the start date in difference we added 1. In beginning of the expression, we used "(int)" to  cast the output to integer value.

I hope that the above information may be useful to you. Please feel free to comment, if you find any correction or you have a better solution.

Thanks!

Wednesday, March 25, 2015

Angular JS: Initializing a controller with a server side run-time value

This problem may look too much difficult for newbies to Angular JS. I was also stucked for some days, googled different websites, but no website could give me any working solution to my problem. Atlast I asked my senior and he helped me to solve this difficult problem in just few minutes.

Problem:

The problem was that I was using multiple partial views on my MVC view. I was trying to use Angular JS for just one of the partial view, whereas, all other views were using server side MVC controller. I had to pass a parameter from server side to my angular JS controller, so that it can get the data based on the parameter.

Solution:

First I tried ngInit approach, but it didn't worked. Every time data function was executing first and then initialize function was executing, as a result undefined parameter was passing to my controller function.

My senior advised me to initialize global variable in javascript on view with the value that I want to pass as a parameter, like this:

//script start

var globalValue = @MyValue;

//script end


then in the angular js controller use this global value like this:

$scope.GetFunctionData(globalValue).then( function() {
.
.
.
}


That's all!

Please write to me whether this solution worked for you. Stay blessed :)

Tuesday, November 18, 2014

Visual Studio Error: Unable to embed resource : Not enough memory to complete the operation

Error:

While building your project in VS 2010, you could get the following error:

Visual Studio Error: Unable to embed resource : Not enough memory to complete the operation

Solution:

This is a common issue in VS 2010, which have been discussed on a lot of forums, but I think nobody is assure about the solution. I get this error today, and took about half an hour to try to resolve it but I got no fruitful result. 

The main reason behind this problem is lack of memory and the project size expansion. Therefore, the Windows runs out of the memory. The quick and temporary solution is to select all files or at least the big-ones (specially the Crystal Reports) from your project using the solution explorer, check if their properties are set as Embedded Resource, change it to Content, then try to run the project. Don't change the files on which you are currently working on. This will prevent VS to embed unnecessary files. But remember, you will have to re-embed these files while building the final version like setup or publishing the project.

Wednesday, October 29, 2014

Nhibernate issue: {"in expected: from blah blah blah" }

Problem:


The exception is:

{"in expected: pc [select pc.parentCategory from ProductCategory pc]"}
[NHibernate.QueryException]: {"in expected: pc [select pc.parentCategory from ProductCategory pc]"}
Data: {System.Collections.ListDictionaryInternal}
HelpLink: null
InnerException: null
Message: "in expected: pc [select pc.parentCategory from ProductCategory pc]"
Source: "NHibernate"
StackTrace: " at NHibernate.Hql.FromParser.Token(String token, QueryTranslator q)\r\n at NHibernate.Hql.ClauseParser.Token(String token, QueryTranslator q)\r\n at NHibernate.Hql.PreprocessingParser.End(QueryTranslator q)\r\n at NHibernate.Hql.ParserHelper.Parse(IParser p, String text, String seperators, QueryTranslator q)\r\n at NHibernate.Hql.QueryTranslator.Compile()\r\n at NHibernate.Hql.QueryTranslator.Compile(ISessionFactoryImplementor factory, IDictionary replacements, Boolean scalar)\r\n at NHibernate.Impl.SessionFactoryImpl.GetQuery(String queryString, Boolean shallow)\r\n at NHibernate.Impl.SessionImpl.GetQueries(String query, Boolean scalar)\r\n at NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters)\r\n at NHibernate.Impl.SessionImpl.Find(String query, Object[] values, IType[] types)\r\n at NHibernate.Impl.SessionImpl.Find(String query)\r\n at Castle.Facilities.NHibernateIntegration.SessionDelegate.Find(String query)\r\n at Cuyahoga.Modules.Ecommer
ce.CatalogueModule.GetSubCategories(Int32 node)\r\n at Cuyahoga.Modules.Ecommerce.Web.CatNav.Page_Load(Object sender, EventArgs e)"
TargetSite: {Void Token(System.String, NHibernate.Hql.QueryTranslator)}


Solution:

There could be several causes for this error, but the main reason behind this error is mapping.

1. Make sure your ClassName.hbm.xml file is set as "Embedded Resource".
2. Make sure table name, column names are correct and their types are correct.

Saturday, July 5, 2014

Creating Student Management System using .Net and Oracle

In Visual Studio .Net, creating a project is not difficult. It allows most of the things to drag and drop. It makes software development quite easy.

Today, we are discussing about how to create a Student Management System in Visual Studio .Net. For this purpose I have used Visual Studio 2008 and Oracle (any version).

First, we will have to create the database. We will use oracle for this purpose.

Below screenshot shows some tables that I have created in Oracle.


You can see, I have used some of the basic tables of this domain and also displayed the relationship among them. You can add or delete tables, fields in the tables, change the relationships as per your requirement.

To create these tables in Oracle we will have to write queries. You can also use some designer like Toad for this purpose. But I have used queries.

Here are the queries to generate these tables and their relationships:

CREATE TABLE COURSES
(
  COURSE_ID     NUMBER(10) PRIMARY KEY,
  TITLE         VARCHAR2(100)   NOT NULL,
  CREDIT_HOURS  NUMBER(5,2)
);

CREATE TABLE DEPARTMENT
(
  DEPARTMENT_ID  NUMBER(10)                    PRIMARY KEY,
  NAME           VARCHAR2(100 BYTE)            NOT NULL
);


CREATE TABLE EMPLOYEE
(
  EMPLOYEE_ID    NUMBER(10)                PRIMARY KEY,
  NAME           VARCHAR2(100)             NOT NULL,
  QUALIFICATION  VARCHAR2(50),
  SALARY         NUMBER(10,2),
  DESIGNATION    VARCHAR2(100),
  DEPARTMENT_ID  NUMBER(10),
CONSTRAINT FK_EMPLOYEE_R01
 FOREIGN KEY (DEPARTMENT_ID)
 REFERENCES DEPARTMENT (DEPARTMENT_ID)
);


CREATE TABLE FACULTY
(
  FACULTY_ID           NUMBER(10)      PRIMARY KEY,
  EMPLOYEE_ID          NUMBER(10)      NOT NULL,
  IS_VISITING_FACULTY  NUMBER(1)       DEFAULT 0    NOT NULL,
CONSTRAINT FK_FACULTY_R01
 FOREIGN KEY (EMPLOYEE_ID)
 REFERENCES EMPLOYEE (EMPLOYEE_ID)
);


CREATE TABLE FACULTY_COURSES
(
  FACULTY_ID  NUMBER(10),
  COURSE_ID   NUMBER(10),
CONSTRAINT FK_FACULTY_COURSES_R01
 FOREIGN KEY (FACULTY_ID)
 REFERENCES FACULTY (FACULTY_ID),
  CONSTRAINT FK_FACULTY_COURSES_R02
 FOREIGN KEY (COURSE_ID)
 REFERENCES COURSES (COURSE_ID)
);


CREATE TABLE EXAMS
(
  EXAM_ID        NUMBER(10)                     PRIMARY KEY,
  SEASON         VARCHAR2(10 BYTE)              NOT NULL,
  YEAR           NUMBER(4)                      NOT NULL,
  EXAM_TYPE      VARCHAR2(10 BYTE)              NOT NULL,
  PASSING_MARKS  NUMBER(10,2)
);


CREATE TABLE EXAM_RESULTS
(
  RESULT_ID       NUMBER(10)                    PRIMARY KEY,
  EXAM_ID         NUMBER(10)                    NOT NULL,
  FACULTY_ID      NUMBER(10)                    NOT NULL,
  COURSE_ID       NUMBER(10)                    NOT NULL,
  STUDENT_ID      NUMBER(10)                    NOT NULL,
  MARKS_OBTAINED  NUMBER(10)                    NOT NULL,
  GPA             NUMBER(4,2),
  STATUS          VARCHAR2(4 BYTE),
CONSTRAINT FK_EXAM_RESULTS_R01
 FOREIGN KEY (EXAM_ID)
 REFERENCES EXAMS (EXAM_ID),
  CONSTRAINT FK_EXAM_RESULTS_R02
 FOREIGN KEY (FACULTY_ID)
 REFERENCES FACULTY (FACULTY_ID),
  CONSTRAINT FK_EXAM_RESULTS_R03
 FOREIGN KEY (COURSE_ID)
 REFERENCES COURSES (COURSE_ID),
  CONSTRAINT FK_EXAM_RESULTS_R04
 FOREIGN KEY (STUDENT_ID)
 REFERENCES STUDENT (STUDENT_ID)
);


CREATE TABLE STAFF
(
  STAFF_ID         NUMBER(10)                   PRIMARY KEY,
  EMPLOYEE_ID      NUMBER(10)                   NOT NULL,
  JOB_DESCRIPTION  VARCHAR2(255 BYTE),
CONSTRAINT FK_STAFF_R01
 FOREIGN KEY (EMPLOYEE_ID)
 REFERENCES EMPLOYEE (EMPLOYEE_ID)
);

CREATE TABLE STUDENT
(
  STUDENT_ID  NUMBER(10)                        PRIMARY KEY,
  NAME        VARCHAR2(100 BYTE)                NOT NULL,
  ADDRESS     VARCHAR2(255 BYTE)                NOT NULL,
  SEMESTER    NUMBER(2)                         NOT NULL
);

CREATE TABLE STUDENT_COURSES
(
  STUDENT_ID  NUMBER(10)                        NOT NULL,
  COURSE_ID   NUMBER(10)                        NOT NULL,
CONSTRAINT FK_STUDENT_COURSES_R01
 FOREIGN KEY (STUDENT_ID)
 REFERENCES STUDENT (STUDENT_ID),
  CONSTRAINT FK_STUDENT_COURSES_R02
 FOREIGN KEY (COURSE_ID)
 REFERENCES COURSES (COURSE_ID)

);


First step is done.

Now we have to create dataset in Visual Studio. For this purpose, open Visual Studio, then Create C# or VB.Net project. Project must be Windows Form type.

Now add a dataset by right clicking on project and then 'Add New Item'. You can find Dataset in Data tab in the window that will be opened.

Right click on the dataset to Add Table, It will ask for your database connection. Create a new connection to your oracle database by providing it the required fields such as Host Name, password, etc. On clicking next button, All the tables of the database will appear. Select the required table, or select all the tables that we have created in the previous step. and click Finish.

Your dataset will be now ready. Compile the program to make sure there is no error. Now you can add database tables/fields to your form. Just open the form, open the Data Sources panel, drag one or more of the data table(s) appearing in it on to the form. You will see a Grid (table) will appear on the form. You can also drop fields instead of grid, by changing it to Details on Datasources panel before dropping.

Compile the program and enjoy :)

Hope you have understand the tutorial, you can feel free to ask any question.

Happy Coding :)

Popular Posts