Friday, December 30, 2011

html encoding table

if you need to search for html encoding table you can go to this link below:

http://www.zytrax.com/tech/web/entities.html


or

http://www.w3schools.com/TAGS/ref_entities.asp


mostly when you googling in the net, what you will find is URL encoding instead of HTML Encoding..

*julie*

Thursday, December 29, 2011

create time duration using c#

Here are the code I created for that purpose:

private string calculateLastUpdate(DateTime dt1, DateTime dt2)
{
string strTimeValue = "";
string timespans;
string[] arrTimespan;
TimeSpan ts = dt1.Subtract(dt2);
timespans = ts.ToString().Replace(":", ".");

if (timespans.Substring(0, 8) == "00.00.00")
timespans = timespans.Substring(9, timespans.Length - 10);
else if (timespans.Substring(0, 5) == "00.00")
timespans = timespans.Substring(6, timespans.Length - 10);
else if (timespans.Substring(0, 2) == "00")
timespans = timespans.Substring(3, timespans.Length - 10);

arrTimespan = timespans.Split('.');

strTimeValue = getTimeUnit(arrTimespan.Count(), Convert.ToInt32(arrTimespan[0]));
return strTimeValue;
}

private string getTimeUnit(int position, int value)
{
string result = "";
switch (position)
{
case 5: result= "day";
if (value / 365 >= 1)
{
result = "year";
value = value / 365;
}
else if (value / 30 >= 1)
{
result = "month";
value = value / 30;
}
else if (value / 7 >= 1)
{
result = "week";
value = value / 7;
}
break;
case 4: result = "hour"; break;
case 3: result = "minute"; break;
case 2: result = "second"; break;
case 1: result = "milisecond"; break;
}


if (value > 1)
result += "s";
result = Convert.ToString(value) + " " + result + " ago";

return result;
}


hope its usefull :)

Wednesday, December 28, 2011

set global variable in javascript

source: http://snook.ca/archives/javascript/global_variable

set the global var using this:

window.myVariable = 1;

instead of
var myVariable = 1;

because sometimes its not working :P

Thursday, December 22, 2011

Open new window using a href

here is the sample code:

<a href="javascript: void(0)"
onclick='javascript:window.open("http://www.google.com");return false;'>New Window</a>

btw if you want to encode your html, can go to this site:


Thursday, December 15, 2011

connect to web service with SLL settings

I got a task to explore an API to get some data to be displayed in a new interface. The problem is the web service is using SSL. Actually the first thing in my mind is using web reference from VS.net, so when I tried to add web reference, there is an error show up like this:

unable to download wsdl file

Tried many times but this error still occurs, then I search in google, and last thing I found is this site: http://debugguru.blogspot.com/2008/06/unable-to-download-wsdl-file-while.html
and indeed it solved the problem, wkwkwk.. Just close the solutions, and reopen, I tried to add web reference again, it works, lol.

But apparently I don't use the web reference. I try to connect to wsdl using Service Reference.
I try to connect, but this error occurs:

Could not establish trust relationship for the SSL/TLS secure channel with authority 'xx.xx.x.xx'.

I search over the net then I found this code:

using System.Net.Security;

using System.Security.Cryptography.X509Certificates;

public class TestUtils

{

public static void OverrideCertificateValidation()

{

ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(RemoteCertValidate);

}

private static bool RemoteCertValidate(object sender, X509Certificate cert, X509Chain chain, System.Net.Security.SslPolicyErrors error)

{

return true;

}

}


Hope it will be useful for you :)

-julie-

working with xml

Few days ago, I got a task to provide a Chart with with the chart highlights which is a brief description of the chart value. To get the chart is easier then to get the values of the chart. '
There are 3 links to get the values from. From the first xml file, I manage to find a way to get the value based on the node name.

Get nodes (and values) after selected node

Dictionary dict = new Dictionary();

private
void getElement(string URLString, string tagName)

{

XmlTextReader reader = new XmlTextReader(URLString);

reader.WhitespaceHandling = WhitespaceHandling.None;

XmlDocument doc = new XmlDocument();

doc.Load(reader);

if ((doc != null))

{

try

{

int i = 0;

XmlNodeList elemList = doc.GetElementsByTagName(tagName);

foreach (XmlNode elem in elemList)

{

for (int j = 0; j < elem.ChildNodes.Count; j++)

{

callChildNode(elem.ChildNodes[j]);

}

i++;

}

}

catch (Exception ex)

{

// exception

throw ex;

}

}

}

private void callChildNode(XmlNode node)

{

if (node.Name != "#text")

if (node.ChildNodes.Count == 1 )

dict.Add(node.Name, node.InnerText);

for (int j = 0; j < node.ChildNodes.Count; j++)

{

callChildNode(node.ChildNodes[j]);

}

}


From the line above, all the nodes with value after the tag that we defined will be listed inside the dictionary. That is for the case if you have a different xml tag that you wish to get the node value from (even if the node inside is the same with the node from the other tag).

------

Get node value based on another node's value

After the first XML, I thought everything is solved, but then when I saw the second XML, it was totally different from the first xml. Dang!! so I have to find a way to get value of a node based on another node's value.

I searched in the internet and got a sample of code from the link below:

http://stackoverflow.com/questions/6203666/xpath-select-a-node-based-on-another-node

Below are the code

var doc = new XmlDocument();
doc.
LoadXml(xmlString);
XmlElement element = (XmlElement)doc.SelectSingleNode("Items/Item[Code='MyCode']/Value");
Console.WriteLine(element.InnerText);


Hope this two code will be useful..

Friday, October 7, 2011

Default value and constrain of a table

So I add a new column to an existing table, and I create it using a command like this:
ALTER TABLE table_name
ADD TagUploader bit not null default 0;

but I then I change my mind, the datatype should be tinyint instead of bit, so I try to alter the table again using this line:
ALTER TABLE table_name
ALTER COLUMN TagUploader tinyint;

but this error message was shown in the message frame:


Msg 5074, Level 16, State 1, Line 1
The object 'DF__PROFILE__tagUplo__6CA31EA0' is dependent on column 'TagUploader'.
Msg 4922, Level 16, State 9, Line 1

ALTER TABLE ALTER COLUMN TagUploader failed because one or more objects access this column.

then I tried to drop the column, still appear a message like this:

Msg 5074, Level 16, State 1, Line 1
The object 'DF__PROFILE__tagUplo__6CA31EA0' is dependent on column 'TagUploader'.
Msg 4922, Level 16, State 9, Line 1
ALTER TABLE DROP COLUMN TagUploader failed because one or more objects access this column.

So the problem is that I create a default value at the creation of that column, that creates a constrain to the table, you can find it in the Constrains folder inside the table's tree
have tried to delete it by right clicking it, then choose delete but an error like this appears:

So I guess the major problem is the constrain, so I search a way to drop the constrain, and yes there is a way, the line was like this:

ALTER TABLE docsadm.profile
DROP CONSTRAINT [DF__PROFILE__tagUplo__6CA31EA0]
GO

After running that script, it will show this message:
Command(s) completed successfully.

Then after that, you can alter the column or even drop the column without any problem anymore. So what I learned from this case is that default value can create a constrain to the table, if you don't need it, just release it.

-thats all folks, says bugs bunny :P-




Tuesday, October 4, 2011

share folder files to be access from asp.net application

So I have a PDF Web Viewer application, its located on server, an usually, the document is put on the same server, so the full path should be like this: C:\folder name\doc folder
and the document can be viewed from client.

Last time I deployed the application to production, they (my customer) said that the file server is on different server, so it will be a share folder, the path is gonna be like this: \\server_name\sharefolder$

Then after I re-setting the application's config into new document folder path, and it result on the my application have access denied. And the condition is, the share folder cannot be granted to everyone, so I set only for Domain\Administrator.

After testing several times, giving the security of the folder to ASPNET user, NETWORK SERVICE user, still doesn't working.

In my desperation, I set Sharing permission to Everyone, and yes it works, but that 's not gonna solve the security issue. Then I tried to set Everyone to Security (not Sharing) and remove the one on Sharing tab, still not work. Then I think, there should be somebody that has to be added on Sharing so it will work, not on Security.
Try to add ASPNET user, but still not working. Then my last chance, NETWORK SERVICE, and tadaaaa.. it works like a charm.

So what I want to say here is, I think we cannot assume that Security is more powerful that Sharing tab. The two of it has it's own behaviour, in this case, the NETWORK SERVICE user has to be added in Sharing tab, not Security. But added in both tab will also works :D

thats all, hope it helps.






update:
Oh yeah, i forgot, there is something you have to set in IIS, gave to the one which have access to that folder. to get to this window, right click on your website, then choose properties.

Saturday, October 1, 2011

error page not found asp.net

so after you have deploy your application to IIS and already set the ASP.NET to the right version, but after you try to browse it, it display Page Not Found.

The problem is... maybe you haven't allowed the .net framework. You have to set the .Net Framework in Web Service Extensions to Allowed instead of Prohibited. That's all.. :)

PS: the Web Service Extensions folder is located in IIS 6, on the bottom of the treeview on left frame.

error when backing up database

this error happens when I was trying to backup SQL Database using scripts:

error Cannot open backup device 'F:\foldername'. Operating system error 5(Access is denied.)

the solutions is:
.
.
.
assign a more powerful user to SQL Server Service

source:
http://social.msdn.microsoft.com/forums/en-US/sqldatabaseengine/thread/021c7aa5-4a8a-4bbb-8ff0-fe6b03920aae/

Saturday, September 3, 2011

Kill Open Transaction in SQL

To check if any open transaction in SQL Server, you can use:

DBCC opentran


after that you will get this result if there is no open transaction:
No active ope
n transactions. DBCC execution completed. If DBCC printed error messages, contact your system administrator.

or else if you have open/uncommited transaction that maybe cause by error in design, you will get this :
Transaction information for database 'db_name'.
Oldest active transaction: SPID (server process ID): 54 UID (user ID) : -1 Name : user_transaction LSN : (1702:160598:3) Start time : Sep 4 2011 12:27:32:713AM SID : 0x0105000000000005150000008cdebb00f310b4f0b1a5950ae8030000 DBCC execution completed. If DBCC printed error messages, contact your system administrator.

If you want to kill the process, remember the SPID, then open the Activity Monitor, then killed it by right clicking on it, then choose Kill Process.

in SQL Server 2000, you can find Activity Monitor in Enterprise Manager, then expand the tree like below picture, the activity monitor will be shown in right frame.

After you right clicked and killed the process, you have to refresh it manually by right clicking on Current Activity - node, then choose Refresh. then open again the Process Info node to see the latest activities.


in SQL Server 2005, Activity monitor can be find in SQL Server Management Studio, inside Management tree node, double clicked it, than a window of processes activity will be show, as picture below:


in SQL Server 2008, Activity monitor were located on the toolbar of SQL Server Management Studio, as shown in picture below:









After you killed the process, you don't have to refresh it, just wait until it disappear from the list in few seconds.

^^