-------------------------------------------------------
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
You will have to do the following in order to achieve an auto incrementing primary key in oracle. First, create a table with a primary key.
CREATE TABLE OwnerSchema.Users
(
UserId NUMBER NOT NULL,
UserName VARCHAR(30) NOT NULL
)
LOGGING
NOCOMPRESS
NOCACHE
NOPARALLEL
NOMONITORING;
COMMIT;
ALTER TABLE OwnerSchema.Users ADD (
CONSTRAINT Users_PK
PRIMARY KEY
(UserId));
COMMIT;
Then create a sequence, this will be used to read the primary key values from.
CREATE SEQUENCE Users_Seq
START WITH 1
INCREMENT BY 1
NOMAXVALUE;
COMMIT;
Finally, create a trigger to auto increment the primary key using the sequence.
CREATE TRIGGER OwnerSchema.Users_Trigger
BEFORE INSERT ON OwnerSchema.USERS FOR EACH ROW
BEGIN
SELECT Users_Seq.NEXTVAL INTO :NEW.UserId FROM Dual;
END;
How to read server response in C#.NET
-------------------------------------------------------
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
The following snippet shows how to read the text/html/xml response from a remote server through .NET code. This technique can be employed as part of a page scrapping service also.
string _strContent = String.Empty;
StreamReader _objSR;
WebResponse _objResponse = null;
WebRequest _objRequest = HttpWebRequest.Create("http://domain.server/Proxy/Controller.aspx?Op=someoperand");
int _contentLength = 0;
_objRequest.Method = "GET";
_objRequest.Credentials = CredentialCache.DefaultCredentials;
_objResponse = _objRequest.GetResponse();
_objSR = new StreamReader(_objResponse.GetResponseStream(), Encoding.ASCII);
_strContent = _objSR.ReadToEnd();
_contentLength = _strContent.Length;
_objSR.Close();
_objResponse.Close();
You can then parse the response as needed for your consumer application.
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
The following snippet shows how to read the text/html/xml response from a remote server through .NET code. This technique can be employed as part of a page scrapping service also.
string _strContent = String.Empty;
StreamReader _objSR;
WebResponse _objResponse = null;
WebRequest _objRequest = HttpWebRequest.Create("http://domain.server/Proxy/Controller.aspx?Op=someoperand");
int _contentLength = 0;
_objRequest.Method = "GET";
_objRequest.Credentials = CredentialCache.DefaultCredentials;
_objResponse = _objRequest.GetResponse();
_objSR = new StreamReader(_objResponse.GetResponseStream(), Encoding.ASCII);
_strContent = _objSR.ReadToEnd();
_contentLength = _strContent.Length;
_objSR.Close();
_objResponse.Close();
You can then parse the response as needed for your consumer application.
System.Data.OracleClient requires Oracle client software version 8.1.7 or greater - Resolved!
-------------------------------------------------------
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
If this .NET exception happens without any reasonable cause, then it might be resolved by re-mapping permissions, at leasyt in my case it did. This error can happen if you have recently upgraded to a newer version of Oracle client (in my case it happenned after I upgraded to 9.2). To resolve this issue follow the following steps.
1. Browse to the Oracle root folder (my case, d:\oracle\Ora92)
2. In this folder's properties window, goto the Security tab and check whether 'Authenticated Users' is present. If not then add this user.
3. Now check the following properties for 'Authenticated Users'. If they are already checked then you must uncheck them first and then re-check them again - this is part of the trick.
-Read & Execute
-List Folder Contents
-Read
4. Next part of the trick is to ensure that in the Advanced permissions section, the 'Authenticated Users' have 'This folder, Sub folder and files' in the Apply To column. Be very careful with what you do in the advanced permissions window as flawed changes might have undesirable effects on rest of the folder hierarchy permissions.
That is all. A system restart was not needed in my case.
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
If this .NET exception happens without any reasonable cause, then it might be resolved by re-mapping permissions, at leasyt in my case it did. This error can happen if you have recently upgraded to a newer version of Oracle client (in my case it happenned after I upgraded to 9.2). To resolve this issue follow the following steps.
1. Browse to the Oracle root folder (my case, d:\oracle\Ora92)
2. In this folder's properties window, goto the Security tab and check whether 'Authenticated Users' is present. If not then add this user.
3. Now check the following properties for 'Authenticated Users'. If they are already checked then you must uncheck them first and then re-check them again - this is part of the trick.
-Read & Execute
-List Folder Contents
-Read
4. Next part of the trick is to ensure that in the Advanced permissions section, the 'Authenticated Users' have 'This folder, Sub folder and files' in the Apply To column. Be very careful with what you do in the advanced permissions window as flawed changes might have undesirable effects on rest of the folder hierarchy permissions.
That is all. A system restart was not needed in my case.
How to execute an EXE executable or a BAT file from .NET code?
-------------------------------------------------------
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
The following code will allow you to invoke and execute an executable file from your program (here it has been written in C#). The WaitForExit() function provides your program control with the capability of synchronous execution. Refer to the 'System.Diagnostics' assembly for utilizing the 'Process' object.
public bool RunExecutable(string strExePath)
{
bool _bSuccess = true; //Assume by default that the executable will run successfully
Process _objProcess = new Process();
_objProcess.EnableRaisingEvents = false;
_objProcess.StartInfo.FileName = strExePath; //Eg, D:\Test\TestProg.exe
try
{
_objProcess.Start();
_objProcess.WaitForExit();
}
catch(Exception e)
{
//If any exception happens during attempted run
_bSuccess = false;
}
return _bSuccess;
}
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
The following code will allow you to invoke and execute an executable file from your program (here it has been written in C#). The WaitForExit() function provides your program control with the capability of synchronous execution. Refer to the 'System.Diagnostics' assembly for utilizing the 'Process' object.
public bool RunExecutable(string strExePath)
{
bool _bSuccess = true; //Assume by default that the executable will run successfully
Process _objProcess = new Process();
_objProcess.EnableRaisingEvents = false;
_objProcess.StartInfo.FileName = strExePath; //Eg, D:\Test\TestProg.exe
try
{
_objProcess.Start();
_objProcess.WaitForExit();
}
catch(Exception e)
{
//If any exception happens during attempted run
_bSuccess = false;
}
return _bSuccess;
}
Website Monitoring Code written in C# .NET
-------------------------------------------------------
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
Today I wrote an alerting tool. The tool would sit as a NotifyIcon on your system tray, and keep monitoring a website to find whether it went down. I will devote writing a windows application to run and be controlled from the system tray at a later post. This post concentrates on just the web URL monitoring.
public bool IsWebSiteDown(string strURL)
{
bool _errorCondition = false;
string _strContent = String.Empty;
StreamReader _objSR;
WebResponse _objResponse = null;
WebRequest _objRequest = HttpWebRequest.Create(strURL);
string _strSource = strServiceIdentifier;
int _contentLength = 0;
try
{
_objResponse = _objRequest.GetResponse();
_objSR = new StreamReader(_objResponse.GetResponseStream(), Encoding.ASCII);
_strContent = _objSR.ReadToEnd();
_contentLength =_strContent.Length;
_strSource = _contentLength.ToString();
_objSR.Close();
_objResponse.Close();
}
catch(Exception e)
{
_errorCondition = true;
}
return _errorCondition;
}
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
Today I wrote an alerting tool. The tool would sit as a NotifyIcon on your system tray, and keep monitoring a website to find whether it went down. I will devote writing a windows application to run and be controlled from the system tray at a later post. This post concentrates on just the web URL monitoring.
public bool IsWebSiteDown(string strURL)
{
bool _errorCondition = false;
string _strContent = String.Empty;
StreamReader _objSR;
WebResponse _objResponse = null;
WebRequest _objRequest = HttpWebRequest.Create(strURL);
string _strSource = strServiceIdentifier;
int _contentLength = 0;
try
{
_objResponse = _objRequest.GetResponse();
_objSR = new StreamReader(_objResponse.GetResponseStream(), Encoding.ASCII);
_strContent = _objSR.ReadToEnd();
_contentLength =_strContent.Length;
_strSource = _contentLength.ToString();
_objSR.Close();
_objResponse.Close();
}
catch(Exception e)
{
_errorCondition = true;
}
return _errorCondition;
}
How to determine if a file is being used by another process?
-------------------------------------------------------
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
Here is a utility function written in C#.NET that can be used to determined whether a file is in use by another process. I used it in one of the file routing windows services that I wrote, you can reuse this as needed. The trick is to request exclusive access to the file using 'FileShare.None' enumeration value. The function will throw an exception if the file is already open by another process.
private bool IsFileInUse(FileInfo objFileInfo)
{
FileStream _objFileStream = null;
try
{
if(objFileInfo.Exists)
{
_objFileStream = objFileInfo.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None);
}
}
catch (IOException)
{
//the file is unavailable because it is:
//still being written to
//or being processed by another thread
return true;
}
finally
{
if (_objFileStream != null)
_objFileStream.Close();
}
//file is not locked
return false;
}
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
Here is a utility function written in C#.NET that can be used to determined whether a file is in use by another process. I used it in one of the file routing windows services that I wrote, you can reuse this as needed. The trick is to request exclusive access to the file using 'FileShare.None' enumeration value. The function will throw an exception if the file is already open by another process.
private bool IsFileInUse(FileInfo objFileInfo)
{
FileStream _objFileStream = null;
try
{
if(objFileInfo.Exists)
{
_objFileStream = objFileInfo.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None);
}
}
catch (IOException)
{
//the file is unavailable because it is:
//still being written to
//or being processed by another thread
return true;
}
finally
{
if (_objFileStream != null)
_objFileStream.Close();
}
//file is not locked
return false;
}
IIS 503 Service Unavailable Problem (One of many)
-------------------------------------------------------
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
The 503 problem can occur due to a variety of reasons. Literature on diferent scenarios is available at the link below. The focus of this article is an issue that occurred with incorrect installation of McAfee Host Intrusion Prevention (disclaimer: this was not a problem with the McAfee software, but is attributed to the way it was installed on the server).
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/55f71614-ef1b-4015-b9c8-a42c1e700c25.mspx?mfr=true
Once you face the 503 issue, the first step is to find out the root cause. First find the actual error logged in the HTTP Error log available on the server path (default location and filename is configurable):
%windir%\System32\LogFiles\HTTPERR
A sample entry is provided below (the IP addresses have been masked for the purpose of my client's privacy):
2009-10-28 16:57:23 10.x.x.xxx 1590 10.xx.xx.xxx 80 HTTP/1.1 GET /testsite/default.aspx?Op=All 503 1 AppOffline TestSiteAppPool
The second last column value 'AppOffline' is of interest as it will tell you exactly why this error occurred. The exact meaning of this word can be found at
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/55f71614-ef1b-4015-b9c8-a42c1e700c25.mspx?mfr=true
For example, 'AppOffline' means the application pool has been put into Rapid Fail Protection and has been disabled automatically. At this point we have pined down the actual issue. In my case this was not sufficient so I looked at the error logs from event viewer and found the following entry:
The HTTP Filter DLL C:\Program Files\McAfee\Host Intrusion Prevention\eng\isapi\IsapiStub.dll failed to load. The data is the error. Data Bytes 7e 00 00 00
Next I checked and found that the above ISAPI filter did not exist. The IIS metabase got modified to route incoming requests to a filter in the Host Intrusion Prevention directory. But the filter was not present on the server due to improper installation performed by our server admin group. We got the Host Intrusion Prevention removed from the server by our server admins and got them to correct their automated installation scripts.
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
The 503 problem can occur due to a variety of reasons. Literature on diferent scenarios is available at the link below. The focus of this article is an issue that occurred with incorrect installation of McAfee Host Intrusion Prevention (disclaimer: this was not a problem with the McAfee software, but is attributed to the way it was installed on the server).
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/55f71614-ef1b-4015-b9c8-a42c1e700c25.mspx?mfr=true
Once you face the 503 issue, the first step is to find out the root cause. First find the actual error logged in the HTTP Error log available on the server path (default location and filename is configurable):
%windir%\System32\LogFiles\HTTPERR
A sample entry is provided below (the IP addresses have been masked for the purpose of my client's privacy):
2009-10-28 16:57:23 10.x.x.xxx 1590 10.xx.xx.xxx 80 HTTP/1.1 GET /testsite/default.aspx?Op=All 503 1 AppOffline TestSiteAppPool
The second last column value 'AppOffline' is of interest as it will tell you exactly why this error occurred. The exact meaning of this word can be found at
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/55f71614-ef1b-4015-b9c8-a42c1e700c25.mspx?mfr=true
For example, 'AppOffline' means the application pool has been put into Rapid Fail Protection and has been disabled automatically. At this point we have pined down the actual issue. In my case this was not sufficient so I looked at the error logs from event viewer and found the following entry:
The HTTP Filter DLL C:\Program Files\McAfee\Host Intrusion Prevention\eng\isapi\IsapiStub.dll failed to load. The data is the error. Data Bytes 7e 00 00 00
Next I checked and found that the above ISAPI filter did not exist. The IIS metabase got modified to route incoming requests to a filter in the Host Intrusion Prevention directory. But the filter was not present on the server due to improper installation performed by our server admin group. We got the Host Intrusion Prevention removed from the server by our server admins and got them to correct their automated installation scripts.
Subscribe to:
Posts (Atom)