Monday, May 25, 2009

Kido Virus (continued)

I guess the virus is not clean yet -.-""""" Still facing the same problems when the computer starts -.-""""" Finally, do a system restore and have everything back. phew...
Share:

Wednesday, May 20, 2009

Kido Virus

This actually has nothing to do with programming, but can't help posting it here. I guess my computer was infected by a virus, tried every way to fix it, none succeeds. I was using Kaspersky antivirus, then one morning when I turn on the computer, the protection is not running, and the update tab disappears.

A virus named Kido has been attacking my computer lately, but after being discovered by Kaspersky, I always delete it.

Not sure, but it should be the Kido that causes the errors on the system. Symptoms:
- Update tab on Kaspersky disappears.
- I was able to open Internet Information Services, but the service is not running, and when I tried running it, it's not responding.
- Cannot open another Internet Information Services or Services.
- Cannot connect to some network parts.
- Cannot open system restore.
- Yahoo Messenger, Meebo Notifier, or MSN Messenger is not running.

I solved it after I found out that there are 2 tasks running on the scheduler, at1 and at2. I notice that they have something to do with the virus which was encountered by Kaspersky, having to do with the Kido (which was deleted successfully by the Kaspersky -.-""""). I deleted both of them.

No sooner had I deleted them, the Messengers are logged in.. Everything goes fine. Phew... Strange case. (Though the update tab on Kaspersky does not appear yet).
Thanx to VX Tools, which helps me figure out there's something wrong with the running processes on the system, otherwise I wouldn't have figured it out only by looking on the task manager.
Share:

Monday, May 18, 2009

Redirecting and hiding URL

Problem : I wanted to make a link that will redirect the users to download a pdf file. Yet, I have to hide the URL, and can't let the users know the URL to the file.

Solution : I use repeater to hide the URL by using CommandArgument and CommandName attributes.

I make a repeater which looks more or less like this on the aspx:


<asp:repeater id="rpt" runat="server" onitemcommand="rpt_ItemCommand" onitemdatabound="rpt_ItemDataBound">
<itemtemplate>
<asp:linkbutton id="linkFileName" runat="server" cssclass="link3"></asp:linkbutton>
</itemtemplate>
</asp:repeater>



Then on the CS:

protected void rpt_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
ClassData classData = (classData)e.Item.DataItem;
LinkButton linkFileName = (LinkButton)e.Item.FindControl("linkFileName");
string fileName = classData.FileName;
linkFileName.Text = fileName;
linkFileName.CommandArgument = classData.FileName;
}
}


protected void rpt_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + e.CommandArgument);
Response.Flush();
Response.WriteFile("D:\folder\" + e.CommandArgument);
Response.End();
}
}
Share:

Error using Server.Transfer

Error : Invalid path for child request 'http://localhost/Content/foldername/pdf_filename.pdf'. A virtual path is expected.

I was using Server.Transfer on links to redirect the web to another page, and this error occured.

Solution : DO NOT user Server.Transfer when redirecting to another web server. Use Response.Redirect instead.
Share:

Cannot create/shadow copy when file already exists

Error : Cannot create/shadow copy '..........' when that file already exists.

Solution : Rebuild solution / Clean solution, then rebuild.

Don't know why this actually happens. But it happens often, after building solution without debugging for times.
Share:

Tuesday, May 12, 2009

Using System.Web.Routing

Use URL Routing on application recently, and find some difficulties when developing.
When opening page which applies URL routing, it shows error that the page doesn't exist.

Should check this point:
Add a wildcard mapping .* to aspnet_isapi.dll and make sure that Check that file exists is unchecked.

Go to IIS, right click the virtual directory of the application, then choose Properties -> Configuration -> Add -> Browse Executable: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 (this path may differ), then find aspnet_isapi.dll, then set the Extension: .*, don't forget to uncheck Check that file exists -> OK.
Share:

Friday, May 8, 2009

Import data from excel to table in SQL

A friend asked about how to import data from Excel to table in SQL, then I searched for it. Found this code. Having tried it, I think it's a nice idea to share it.

INSERT INTO Table_Name
SELECT column1, column2
FROM OPENROWSET ('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=C:\ExcelTable.xls', 'SELECT * FROM [Sheet1$]')
Share:

Thursday, May 7, 2009

Read & Write .ini files

Reading from and writing to .ini files is very useful and is a widely used method to set or get some uncertain keys, such as database location, period, or any other things that are common, but are subject to change.

It is not necessarily .ini files. The extension may vary, depends on the developer will, but .ini is the most commonly used extension.

It's actually quite simple, with the utilization of API. API is very useful in VB. It can do a lot of things can't be done using classical VB components.

1. Make a text files with the format specified below: name it test.ini, and put it in the same folder where the application is made.

[Header_Key1]
key1=value1
key2=value2
...
[Header_Key2]
key3=value3
...

where:
Header_Key1, Header_Key2 are the keys used for a group of keys.
key1, key2, key3 are the keys of the values to be read and written.

e.g. (To get current period and semester from text files)
[Period]
Period=2009
Semester=2
[Content]
AnotherContent=this is that other content


2. Make a module and put the following functions (to read and write text files) into the module:

Option Explicit
Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" _
(ByVal lpApplicationname As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" _
(ByVal lpApplicationname As String, ByVal lpKeyName As Any, ByVal lsString As String, ByVal lplFilename As String) As Long


Function GetfromINI(SectionHeader$, VarName$, FileName$) As String
Dim RetStr As String
RetStr = String(255, Chr(0))
GetfromINI = Left(RetStr, GetPrivateProfileString(SectionHeader$, ByVal VarName$, "", RetStr, Len(RetStr), FileName$))
End Function


3. To get the value of the keys on the .ini files :
Objects used:
3 textboxes named Text1, Text2, Text3
Dim isi1 As String, isi2 As String, isi3 As String

isi1 = GetfromINI("Period", "Period", App.Path + "\test.ini")
isi2 = GetfromINI("Period", "Semester", App.Path + "\test.ini")
isi3 = GetfromINI("Content", "AnotherContent", App.Path + "\test.ini")
Text1.Text = isi1
Text2.Text = isi2
Text3.Text = isi3


4. To save the value on textbox to the .ini files :
Objects used:
3 textboxes named Text1, Text2, Text3

WritePrivateProfileString "Period", "Period", Text1.Text, App.Path + "\test.ini"
WritePrivateProfileString "Period", "Semester", Text2.Text, App.Path + "\test.ini"
WritePrivateProfileString "Content", "AnotherContent", Text3.Text, App.Path + "\test.ini"



That's all.
Share:

Wednesday, May 6, 2009

Browser asks for username & password while debugging

Problem : The browser keeps asking for username and password while debugging.

Solution :
1. Check on IIS if you're using IIS, by pressing window + R, then type "inetmgr" without quotes. Go to the website on the default web site. Then right click, properties, on directory security, check Anonymous Access, and make sure you also check Integrated Windows Authentication.

2. Make sure the application being developed is not located on shared folders such as My Documents, Desktop, etc. If it is indeed on one of those folders, move it to another folder on the local drive, e.g. C:\, D:\, etc.
Share:

ADO: Recordcount return -1

Error : Recordcount May Return -1 while using ADO connection

The problem is ADO defaults to a Server side cursor. You can only use the RecordCount property with a Client side Cursor.

Do something like...
rsMyRecordset.CursorLocation = adUseClient

If I may guess, the reason the RecordCount doesn't work in your code is that the default cursortype, adOpenForwardOnly, of the recordset doesn't support it. ForwardOnly recordsets ("firehose cursors") are very fast when you just want to run through them from top to bottom. So, if you are using adOpenForwardOnly for the cursorType, you may have to change it.

Here's the code:

rs.CursorLocation = adUseClient
rs.Open sql, con, adOpenKeyset, adLockPessimistic
Share:

Friday, May 1, 2009

Generate random characters

There is a way to generate random characters in a simple way, just use :
select NEWID()


This function is quite useful in some occasions, though may not be it's main usage.
e.g. If you're going to generate a random quote from a table named MsQuote :
SELECT TOP 1 QuoteId, QuoteText
FROM MsQuote
ORDER BY NEWID()
Share:

Stored procedure's dependencies

Find the dependencies of a stored procedure / Find tables used in a stored procedure:
use sp_depends sp_name
Share:

Sys on SQL

Not sharing query, but some tips that might be useful when looking for a needle in a haystack.
Am using Microsoft SQL Server 2000, but won't differ too much on later versions, I guess.

Find tables with the specified name

-----------------------------------
select name from sysobjects where name like '%table_name%' and type = 'u'



Find stored procedures with the specified name
----------------------------------------------
select name from sysobjects where name like '%sp_name%' and type = 'p'



Find the name of the tables which contain specified column
----------------------------------------------------------
select TableName = a.name, ColumnName = b.name from sysobjects a, syscolumns b
where a.id = b.id and b.name = 'column_name'



Find stored procedures which contain certain key / text
-------------------------------------------------------
select name from sysobjects where id in ( select id from syscomments where text like '%text_in_sp%')

This is also useful when you would like to search for stored procedures which uses a certain table.
e.g. If you would like to know the stored procedures which use the table named table_name,
select name from sysobjects where id in ( select id from syscomments where text like '%table_name%')
Share:

You may be intersted in

Related Posts

Updating Table Containing Xml Column via LinkedServer

If you are trying to update a table containing XML column via Linked Server in SQL Server, and you are not able to, you are not alone. There...

About Me

My photo
Is an ordinary man, with a little knowledge to share and high dreams to achieve. I'd be glad if I can help others, 'coz the only thing for the triumph of evil is for a good man to do nothing.

About Blog

You can find a lot of debugging and deploying problems while developing applications in .NET and Visual Basic here. There are also some querying tips in SQL and typical source codes which might be useful shared here.

Popular Posts

Blogroll

Followers

Leave a Message