Search This Blog

SQLLDR & C# .Net

Loading data through SQLLDR (SQL* Loader) from C# .Net

Problem :
Load comma seperated data into tables.

Solution:
Best way is SQL Loader "SQLLDR"

DOS/Oracle Part:
How to use SQL Loader from Command line:
SQLLDR UserName/Password@TNS_DBName CTLFILE=anyFile BADFILE=anyOtherName
  • SQLLDR = SQL Loader
  • User Name = User Name of Oracle Db.
  • Password = Password of Oracle Db
  • TNS_DBName = TNS Entry of DB instance
  • CTLFILE => CtlFile is file where you will write actual load process
  • BADFILE => BadFile will be generated by process, for records which are not updated.
Following is an example of CTLFILE
LOAD DATA
INFILE dataFile.csv
BADFILE dataFile.bad
APPEND INTO TABLE myTableName
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
(id,name,email)
Where
  • dataFile.csv  : is data file, you can replace it with yours.
  • FIELDS TERMINATED BY ',' : You are telling process that fields are terminated by comma (your format)
  • (id,name,email)  : column names, seperated by comma.

C# calling part:
To write a fancy code:
  • First write this CTL file dynamically (using FileStream class)
  • then to call SQLLoader use following code: (code has comments so it is pretty much self explanatory)
using System.Diagnostics;

Function is :
//public function ExecuteLoader() (of DataLoader class---Names given by me :) )

Process p = new Process();
 string myCommand = @"CMD.EXE";
 p.StartInfo = new ProcessStartInfo(myCommand); 
 //Provide arguments to CMD.EXE
 p.StartInfo.Arguments = @"/c SQLLDR SALMAN/SALMAN@CODE4CODER CONTROL=C:\CODE4CODER\TestFile.txt";

//To read output of process (before error)
p.StartInfo.RedirectStandardOutput = true;

//To read output of process(after error)
p.StartInfo.RedirectStandardError = true;
           
p.StartInfo.UseShellExecute = false;
           
p.StartInfo.WorkingDirectory = @"c:\WorkingFolder\";
p.Start();
p.WaitForExit();

if (p.ExitCode == 0){ //Success
    string standardOutputString = p.StandardOutput.ReadToEnd();
    //Show standard output (before error)
    MessageBox.Show(standardOutputString);
}
else
{
   string errorString = p.StandardError.ReadToEnd();
   //Show output if there is any error
   MessageBox.Show(errorString);
 }

PS: This is totally my own code, if you want to copy you are free, but if you posting it to your blog, please refer http://code4coder.com as source.
Keywords : C#, ASP.Net, SQLLDR, .Net,VB.Net, C Sharp, Loading data in oracle, Oracle, PL/SQL, calling cmd with parameters,System.Diagnostics,SQLLDR,shell execution through C#, .Net, .Net, C#, calling cmd with parameters, code4coder, Diagnostics, load csv data in table, load data,oracle,process,ProcessStartInfo,shell script C#,slq loader,sql,SQLLDR,System.Diagnostics
Reflection,System.Reflection,Creating objects dynamically trhough reflection, code4coder.com,code4coder, c#,asp.net,vb.net,pl/sql,advanced features, code, coder, coders, reflection,system.reflection,System,using System.Reflection,Assembly,ConstructorInfo,Object,MethodInfo,Convert.ToString(),asp,slq,optimized code,email,sqlldr,Invoke,Type,Type[],Ajax,Cell Phone, Mobile Phone, Coding, Code,using System, using System.Collections, using System.Net, Constructor, Destructor, Object oriented programming, ebook, learning, UMT, code, freak, programmer, programmer's heaven, sql, optimization query, best SQL query writing, Query SQL, Best practices, Problems, Issues, C#, .Net, . Net, C# .Net, C#.Net, VC, VC#,Threads,Multithreading,Trim(),javascript, jScript, JavaScript, jQuery, client site, server side, client, server, group by, order by, max() over, count() over, dense_rank(), rank(), dense_rank, rank, Email, SQLLDR,C# help, help, coding help, HP, Application, Software Engineer

Parse Error - While compiling / debugging ASP.Net application

Working in .Net 2.0, Recently, I came across one problem; a FIPS (Federal Information Processing Standards) related error on the .aspx pages which were having debug=”true”.

My ASP.net application was hosted on IIS7 running on WindowsXP. further I was using Visual Studio 2005 Professional Edition. Even I was not able to compile my project.

Error was:
“Parser Error Message: This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms.” when .net page has debug=”true”

and Error screen-shot was:


To resolve the problem,

(1) Goto Run window in Start Menu and type "regedit" to open Registry editor.
(2) Find key fipsalgorithmpolicy in [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa]
Its value would be dword:00000001 => which mean
(3) Remove key "fipsalgorithmpolicy"

Enjoy

PS:
(1) When I fixed this problem by searching online, I thought to share on blog and wrote it in my words. Originally this solution is not identified by code4coder.com
(2) @Code4Coder we share day to day programming issues and problems in .Net, C#, ASP.Net (Ajax, JavaScript, jQuery, WebForms, WebServices), VB.Net, Oralce SQL, Oracle PL/SQL.

AJAX & .Net

AJAX & .Net

AJAX is abbreviation of "Asynchronous JavaScript and XML". AJAX is based on JavaScript and HTTP requests. Using Ajax in .Net is really simple and easy. Very basic steps:

Suppose our class name of webform is : MyWebForm1
(1) Add Ajax.dll in website project referrence.
(2) Register class on PageLoad for Ajax.
(3) Mark methods that can be called through AJAX.
(4) Call server side methods : Synchronously/ASynchronously
(5) Manipulate returned value

Here we go:
(1) Add Ajax.dll in website project:
            As we add any other reference in website, add this reference also :)

(2) Register class for Ajax use on page load:
In page load event handler : (C#)
protected void Page_Load(object sender, EventArgs e)
add: Ajax.Utility.RegisterTypeForAjax(typeof(MyWebForm1));      

(3) Mark method that can be called through AJAX: (C#)
[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.ReadWrite)]
public int GetSquareAjax(int val) { return val * val; }

(4a) In JavaScript : To call a server side method ASynchronously, call method
as
val returnValue = MyWebForm1.GetSquareAjax(44).value;
where
  • MyWebForm1 = Type
    registered for AJAX in Page Load of webform
  • GetSquareAjax
    = MethodName
  • 44 = Parameter
    Value
  • returnValue = will have returned value.

(4b) In JavaScript : To call a server side method ASynchronously, call method
as
MyWebForm1.GetSquareAjax(44, ServerCallBack_GetSquareAjax);         
where
MyWebForm1 = Type registered for AJAX in Page Load of webform
  • GetSquareAjax
    = MethodName
  • 44 = Parameter
    Value
  • ServerCallBack_GetSquareAjax
    = Call back function (should be written in javaScript)
 

this Call back function can be like:
function ServerCallBack_GetSquareAjax(ajaxReturnValue){
}

Note in above function there is one parameter; named= ajaxReturnValue. This is object and
have following properties:
  • request
  • error
  • value
  • context

Most important amoung these
properties are
  • value
  • error

'value' will have return value (Note if object is returned from server then 'value' property will have all exposed
properties of returned object.

'error' will have error value (if there is any error on server side)
           
 

PS : Please note that due to
hosting issues of code4coder group, right now we cannot upload examples/code
right now. We are working on it.



Reflection,System.Reflection,Creating objects dynamically trhough reflection, code4coder.com,code4coder, c#,asp.net,vb.net,pl/sql,advanced features, code, coder, coders, reflection,system.reflection,System,using System.Reflection,Assembly,ConstructorInfo,Object,MethodInfo,Convert.ToString(),asp,slq,optimized code,email,sqlldr,Invoke,Type,Type[],Ajax,Cell Phone, Mobile Phone, Coding, Code,using System, using System.Collections, using System.Net, Constructor, Destructor, Object oriented programming, ebook, learning, UMT, code, freak, programmer, programmer's heaven, sql, optimization query, best SQL query writing, Query SQL, Best practices, Problems, Issues, C#, .Net, . Net, C# .Net, C#.Net, VC, VC#,Threads,Multithreading,Trim(),javascript, jScript, JavaScript, jQuery, client site, server side, client, server, group by, order by, max() over, count() over, dense_rank(), rank(), dense_rank, rank, Email, SQLLDR,C# help, help, coding help, HP, Application, Software Engineer