-------------------------------------------------------
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
A few months earlier, I was setting up a web service library which would contain multiple versions of the same web service. The business behind hosting multiple versions of the same service was that if any changes were made to the web service to alter the input or output then a new version would have to be hosted which would be used as the active version of the service. This strategy took care of backward compatibility in systems that were already consuming the sevice and saved significant cost of quality and testing.
The web services would look something like below in the IIS (real application names have been masked).
IIS Root
|__AppName.ModuleName.WebServices
|__v1.0
|__ServiceName.asmx
|__v1.1
|__ServiceName.asmx
|__v1.2
|__ServiceName.asmx
-Each service version would contain 3 files:
(1) a DLL in the /bin folder
(2) an ASMX file and
(3) a WEB.CONFIG file.
-Each service version would be configured as an APPLICATION in IIS.
-All the services would connect to the same database (Oracle in this case).
-In the WEB.CONFIG file connection pooling would be true and pool size set to 25.
-The total number to allowed connections to the database was set to 300.
Now, there is a technical consideration to be made while this web hosting is done. Everytime a version of the service is hit for the first time, it will block 25 (pool size) connections. So if simultaneously two versions of the service hit the database then 50 connections will be blocked. Theoretically, 300 connections would be able to support only 300/25 = 12 versions of the service hitting simultaneously. This meant that if there is ever more than 12 versions of the same service hitting the database simultaneously, then the first 12 services will succeed. What happens to the 13th request - well I guess it will error - but I haven't tested it out. If you happen to read my article and test it please post the results.
In my case, a workaround was adopted - we simply decided to turn off connection pooling on the earlier versions and keep it active only in the most recent version.
Finding Oracle Tablespace Utilization (Free v/s Consumed space)
-------------------------------------------------------
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
Last week I was working on my project when we discovered that space monitoring was not active in our application's database. During the process of addressing this problem, I figured out how we can easily query the database to get a report on various tablespaces and their free space. The query I used is provided below (the results are in MBs), the Oracle version I used was 10g.
SELECT
tablespace_name,
SUM(space)/1024/1024 "Size MB",
SUM(free)/1024/1024 "Free MB",
(1-(sum(free)/1024/1024)/(sum(space)/1024/1024))*100 "% Used"
FROM
(
SELECT
tablespace_name,
sum(bytes) space,
0 free
FROM dba_data_files
GROUP BY tablespace_name
UNION
SELECT
tablespace_name,
0 space,
sum(bytes) free
FROM dba_free_space
GROUP BY tablespace_name
)
WHERE TABLESPACE_NAME like UPPER('%')
GROUP BY tablespace_name
order by (1-(sum(free)/1024/1024)/(sum(space)/1024/1024))*100;
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
Last week I was working on my project when we discovered that space monitoring was not active in our application's database. During the process of addressing this problem, I figured out how we can easily query the database to get a report on various tablespaces and their free space. The query I used is provided below (the results are in MBs), the Oracle version I used was 10g.
SELECT
tablespace_name,
SUM(space)/1024/1024 "Size MB",
SUM(free)/1024/1024 "Free MB",
(1-(sum(free)/1024/1024)/(sum(space)/1024/1024))*100 "% Used"
FROM
(
SELECT
tablespace_name,
sum(bytes) space,
0 free
FROM dba_data_files
GROUP BY tablespace_name
UNION
SELECT
tablespace_name,
0 space,
sum(bytes) free
FROM dba_free_space
GROUP BY tablespace_name
)
WHERE TABLESPACE_NAME like UPPER('%')
GROUP BY tablespace_name
order by (1-(sum(free)/1024/1024)/(sum(space)/1024/1024))*100;
Dynamically Parsing Fields/Columns From a DataReader
-------------------------------------------------------
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
Today I was faced with a situation where I had to write a data layer function using ADO.NET that would be able to read the resultset from a stored procedure irrespective of number of field/columns and their names. And eventually serialize the stored procedure output for consumption through a web service. Here is the code listing:
-------------------------------------------------------
public DataSet GetDataTableFromReader(string strDataSetName, string strDataTableName, OracleDataReader objReader)
{
DataSet _dsResult = new DataResult(strDataSetName);
DataTable _dtResult = new DataTable(strTableName);
DataRow _dtRow;
DataColumn _dc = new DataColumn();
for (int i = 0; i < objReader.FieldCount; i++)
{
_dc.ColumnName = objReader.GetName(i);
_dtResult.Columns.Add(_dc);
_dc = new DataColumn();
}
if (objReader.HasRows)
{
while (objReader.Read())
{
_dtRow = _dtResult.NewRow();
for (int i = 0; i < objReader.FieldCount; i++)
{
_dtRow[objReader.GetName(i)] = objReader[objReader.GetName(i)];
}
_dtResult.Rows.Add(_dtRow);
}
_dsResult.Tables.Add(_dtResult);
}
_dc.Dispose();
_dtRow = null;
_dtResult.Dispose();
return _dsResult.GetXML();
}
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
Today I was faced with a situation where I had to write a data layer function using ADO.NET that would be able to read the resultset from a stored procedure irrespective of number of field/columns and their names. And eventually serialize the stored procedure output for consumption through a web service. Here is the code listing:
-------------------------------------------------------
public DataSet GetDataTableFromReader(string strDataSetName, string strDataTableName, OracleDataReader objReader)
{
DataSet _dsResult = new DataResult(strDataSetName);
DataTable _dtResult = new DataTable(strTableName);
DataRow _dtRow;
DataColumn _dc = new DataColumn();
for (int i = 0; i < objReader.FieldCount; i++)
{
_dc.ColumnName = objReader.GetName(i);
_dtResult.Columns.Add(_dc);
_dc = new DataColumn();
}
if (objReader.HasRows)
{
while (objReader.Read())
{
_dtRow = _dtResult.NewRow();
for (int i = 0; i < objReader.FieldCount; i++)
{
_dtRow[objReader.GetName(i)] = objReader[objReader.GetName(i)];
}
_dtResult.Rows.Add(_dtRow);
}
_dsResult.Tables.Add(_dtResult);
}
_dc.Dispose();
_dtRow = null;
_dtResult.Dispose();
return _dsResult.GetXML();
}
Sideways Sliding DIV (Animated Sideways Sliding Panel in Javascript)
-------------------------------------------------------
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
Last week I was in need of a DIV that could slide sideways. My search on the internet led me to an useful article on up and down sliding DIV by Harry Maugans. But I could not find a sideways sliding DIV that could be readily used. So I decided to write my own. The JS code is listed below.
Start out by placing a hyperlink and a DIV on your web page, as shown below.
Next, place the following javascript code within the head tag of your web page. Just remember to remove all the BR tags from the JS code below :)
And of course don't forget to initialize the the DIV on page onload event by calling the Init function.
Goto blog home
Visit my new blog dedicated to Internet of Things, Embedded Programming & Automation
-------------------------------------------------------
Last week I was in need of a DIV that could slide sideways. My search on the internet led me to an useful article on up and down sliding DIV by Harry Maugans. But I could not find a sideways sliding DIV that could be readily used. So I decided to write my own. The JS code is listed below.
Start out by placing a hyperlink and a DIV on your web page, as shown below.
Next, place the following javascript code within the head tag of your web page. Just remember to remove all the BR tags from the JS code below :)
And of course don't forget to initialize the the DIV on page onload event by calling the Init function.
Auto Incrementing Primary Key in ORACLE
-------------------------------------------------------
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;
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.
Subscribe to:
Posts (Atom)