Monday, March 20, 2006

A lot of IIS restarts. Strange behavior!

Suddenly, one app goes slowly...

Watching the IIS log of one of our application, all I can found was a lot of IIS restarts. Digging into the IIS configurations, app code and all I can suppose I can't found any result.

Then I try to test the app in debug mode, and all I can find was a error like this:
"An unhandled exception of type 'System.Threading.ThreadAbortException' occurred in Unknown Module.

Additional information: Subproceso anulado.
"

Well... the IIS restarts any time I wrote into the MS Access database. Perhaps a problem with the ODBC?... No

Resolution:
The problem was that someone had taken the decision to put the database into the bin directory for avoiding web downloads of it and ensuring IIS read/write permissions. Bad Idea!!!. Why? Because IIS has a file watcher to the bin and its subdirectories, and when one file into them changes IIS recycles the appDomain.

How can you avoid web downloads of some of your files?

1. Open the Web.config file in a text editor such as Notepad. The Web.config file is located in the root directory of your Web application.

2. In the Web.config file add the configuration element under the element.
Note You must not copy the element from the Machine.config file. The reason you must not copy the element is because the element permits you to add additional file types without completely overriding the Machine.config settings.

3. In the element, use sub tags to specify additional file types that you want blocked. Set the verb attribute equal to “*”. When you do this, you specify that all types of HTTP requests are blocked. Define the path attribute as a wildcard character that matches the types of files you want to block. For example, you may specify “*.mdb”. Finally, set the type attribute to “System.Web.HttpForbiddenHandler". The code sample that follows shows how to configure the "httpHandlers" section in the Web.config file.


<system.web>
  <httphandlers>
    <add type="System.Web.HttpForbiddenHandler" path="*.mdb" verb="*" />
    <add type="System.Web.HttpForbiddenHandler" path="*.csv" verb="*" />
  </httphandlers>
</system.web>


4. Save the Web.config file. The ASP.NET application automatically restarts.


Permalink: A lot of IIS restarts. Strange behavior! 

Saturday, March 05, 2005

JPG image support in MIDP. How to detect it in J2ME

(Soporte para imagenes JPG en MIDP. Como detectarlo en J2ME)

At my last project we have to show certain downloaded images in a mobile phone using J2ME. The images are in jpeg format, and we pass them throughout an adapter for preprocess the width and the format.

As they are camera images, if we send to the phone in png format, they has more or less 15 KB, but if we send them in jpg, only 3 or 4 KB are needed, but...

As MIDP standard says:

"...Implementations are required to support images stored in the PNG format, as specified by the PNG (Portable Network Graphics) Specification, Version 1.0. All conforming MIDP implementations are also conformant to the minimum set of requirements given by the PNG Specification."

Well, to manage those problem we execute the following routine when the application loads.

boolean support_JPG = false;
try{
  Image img = Image.createImage("/res/p.jpg");
  support_JPG= true ;
  img = null;
  System.out.println("JPG support is true");
catch(Exception e){
    System.out.println("JPG support is false");
}

They idea is put a small pixel jpeg file(160 bytes) in the resources and try to load it, and if no exception is thrown, we suppose that the jpg format is supported by the phone, and we store this value in a boolean variable called support_JPG. Another thing thath you can do, is call this routine only the first time that the app runs in the phone and store this value using RMS(Recommended).


Permalink: JPG image support in MIDP. How to detect it in J2ME 

Tuesday, March 01, 2005

ILUNGA, the world's most difficult word to translate

(ILUNGA, la palabra mas dificil de traducir)

The world's most difficult word to translate has been identified as "ilunga" from the Tshiluba language spoken in south-eastern DR Congo.

Ilunga means "a person who is ready to forgive any abuse for the first time, to tolerate it a second time, but never a third time".

It seems straightforward enough, but the 1,000 language experts identified it as the hardest word to translate.

In second place was shlimazl which is Yiddish for "a chronically unlucky person".

Third was Naa, used in the Kansai area of Japan to emphasise statements or agree with someone.


Permalink: ILUNGA, the world's most difficult word to translate 

Tuesday, February 22, 2005

Napster's DRM just cracked

(El DRM de Napster ya ha sido roto)

0. Download and install Napster, sign up for 14 day free trial.

1. Download and install the latest version of Winamp, or if that doesn't work, get an older version

2. Download and install the Winamp Plug-in Output Stacker

3. Open Winamp Options->Plug-ins->Output->Dietmar's Output Stacker->Configure
    a. Add out_ds.dll from Winamp/Plug-ins folder
    b. Add out_disk.dll from Winamp/Plug-ins folder
    c. Select out_disk.dll in the Output Stacker->Configure
    d. Set the output directory and output file mode to Force WAV file
    e. Exit preferences

4. Load downloaded Napster protected WMAs into your Winamp playlist

5. Press play and each file will be converted to WAV as it plays

6. Burn WAVs to CD with your favorite burning program

this post was totally copied from http://blog.kordix.com/marv/archives/000400.html. Three computers, one fast networked drive, and a few dedicated people: Turning Napster's 14 day free trial into 252 full 80 minute CDs of free music.


Permalink: Napster's DRM just cracked 

Tuesday, February 15, 2005

Nokia and Microsoft put music and music stores on mobile phones worldwide

(Nokia y Microsoft ponen musica y tinedas de musica en los telefonos moviles)

In a deal that lays the groundwork for the next generation of mobile entertainment, Loudeye, Nokia and Microsoft have unveiled an alliance that will put music and music stores on mobile phones worldwide, making cell phones a viable alternative to music players like the iPod, reports Reuters.

"Wireless operators in the United States and more than 30 other countries now can offer their own branded mobile music services to subscribers that consumers can access using their phones and their PCs interchangeably".


Permalink: Nokia and Microsoft put music and music stores on mobile phones worldwide 

Wednesday, February 09, 2005

Super Bowl 2005 Ads

(Anuncios de la Super Bowl del 2005)

Here you can find all the commercials from Super Bowl XXXIX.

The advertisers are: Paramount Pictures, Anheuser Busch, Ameriquest Mortgage Company, Buena Vista Pictures, CareerBuilder.com, Cialis, Silestone (A spanish company), DirecTV, Emerald Nuts of California, FedEx, Frito Lay, General Motors, GoDaddy.com, Heineken, Honda, MBNA, Mastercard, McDonalds, MGM, Degree, McIlhenny Tabasco, Michelob, Microsoft, Napster, NFL, Novartis Ciba Vision, Olympus, Pepsi, Pizza Hut, Quizno's, Sony Pictures, Subway, 20th Century Fox, Toyota, Warner Bros., Visa, Volvo, Ford Mustang, Ford Truckm, Verizon Wireless and Bubblicious.



Permalink: Super Bowl 2005 Ads 

Tuesday, January 25, 2005

Publishing a teletext in Internet

(Publicando un teletexto en Internet)

In my last project I have published in Internet the teletext of two of the most important Spanish television channels. The project was based on .Net technology and Sysmedia PLANET Web Gateway, which provides the automatic publishing of teletext services to the web, exporting the teletext to GIF or XML files.

Those channels are:
Telecinco teletext
TeleMadrid teletext


Permalink: Publishing a teletext in Internet 

Friday, January 14, 2005

Strange strings in user agents

(Cadenas extrañas en los user agents)

Seeing the logs of an IIS server, I have found a lot of user agents with very strange strings added to the normal user agent string.

For example:

Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; ESB{A8417D9D-5087-4807-9D73-9E09290256CD})
Mozilla/4.0+(compatible;+MSIE+5.5;+Windows+NT+4.0;+H010818)
Mozilla/3.0 (compatible; HP Web PrintSmart 04b0 1.0.1.34)
Mozilla/4.5 (compatible; HTTrack 3.0x; Windows 98)

Searching in google, I found this web http://www.zytrax.com/tech/web/browser_ids.htm#mystery.

Most of them are Browser Help Objects and other are spyware



Permalink: Strange strings in user agents 

Friday, December 24, 2004

Get the primary key(ID) of the last inserted record in Access and SQL Server

(Obtener la clave primaria(ID) del ultimo registro insertado en Access y SQL Server)

One of the most common things that you have to do when you are working with databases is taking the primary key of the last inserted record. Usually, after making the insert, you make another query with the same parameters that you use in the insert for taking the primary key of the inserted record.

There is 3 solutions:

1) SELECT @@IDENTITY(MS Access and SQL Server)

I have tested it in MS Access and SQL Server with a desktop app and with some store procedures having the correct values in both cases, BUT it doesn't work well in any other cases, because it returns the last IDENTITY value produced on a connection, regardless of the table that produced the value, and regardless of the scope of the statement that produced the value. So if you made 2 inserts and you want get the id of the first one, Select @@identity returns to you the id of the second insert. Another problem is if you insert a value in a table, and this insertion throws a trigger which makes an insert in another one table. In this case SELECT @@IDENTITY returns the ID of this second table.

2) SELECT IDENT_CURRENT('tablename')(only SQL Server 2000)
This new function returns the last IDENTITY value produced in a table, regardless of the connection that created the value, and regardless of the scope of the statement that produced the value.

3) SELECT SCOPE_IDENTITY()(only SQL Server 2000)
This new function returns the last IDENTITY value produced on a connection and by a statement in the same scope, regardless of the table that produced the value.

For more information read http://www.databasejournal.com/features/mssql/article.php/3307541



Permalink: Get the primary key(ID) of the last inserted record in Access and SQL Server 

Friday, December 10, 2004

DOCTYPE and XML declarations. Headers and document definitions

(DOCTYPE y declaraciones XML. Cabeceras y definiciones de documentos)

Via this web I found a lot DOCTYPEs of markup languages(I have added someone).

If you have fought with mobile phones, you have found a lot of problems with this.

Let's see the rest of the page and the following pages, it's excellent. It has an interesting relationship about how tags must be used in those languages.

A lot of work waiting for you!!!


WML 1.1
<?xml version="1.0"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml11.dtd"><wml>

WML 1.2
<?xml version="1.0"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml12.dtd"><wml>

WML 1.3
<?xml version="1.0"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN" "http://www.wapforum.org/DTD/wml13.dtd"><wml>

WML 2.0
<?xml version="1.0"?><!DOCTYPE html PUBLIC "-//WAPFORUM//DTD WML 2.0//EN" "http://www.wapforum.org/dtd/wml20.dtd" ><html xmlns="http://www.w3.org/1999/xhtml" xmlns:wml="http://www.wapforum.org/2001/wml">

XHTML 1.0
<?xml version="1.0"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

XHTML Basic
<?xml version="1.0"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd"><html xmlns="http://www.w3.org/1999/xhtml xml:lang="en" lang="en">

XHTML-MP-WAP
<?xml version="1.0" encoding="UTF-8"?>lt;!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"><html xmlns="http://www.w3.org/1999/xhtml">

HTML 4.01
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><HTML>

HTML 4 Mobile
<!DOCTYPE HTML SYSTEM "-//W3C//DTD HTML 4.0//EN" "html40-mobile.dtd"><HTML>

cHTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD Compact HTML 1.0 Draft//EN"><HTML>

i-mode 3.0
<!DOCTYPE HTML PUBLIC "-//W3C//DTD Compact HTML1.0 Draft//EN"><HTML>

Palm Web Clipping
<!DOCTYPE HTML PUBLIC "-//POS//DTD Palm OS HTML 3.2 Final//EN"><HTML>



Permalink: DOCTYPE and XML declarations. Headers and document definitions  

Thursday, November 25, 2004

Speed up Acrobat Reader 6 start up

(Acelerar el arranque del Acrobat Reader 6)


The first trick is don't load all plug-ings provided by the Acrobat Reader or third party at the start up.

How to do it?
Go to the folder where the Acrobat is installed, usually "C:\Program Files\Adobe\Acrobat 6.0\Reader".

Take the plug-ins from the plug_ins folder and put them in the optional directory. This way the plug-ins will still work, they just won't be loaded at startup.

Don't move the EWH32.api and Search.api plug-ings. As far as I know they are the integration with the browser and the search API.

The second trick is turn off the Splash screen:
Edit - Preferences - Startup then uncheck the box named Display Splash screen.


Permalink: Speed up Acrobat Reader 6 start up 

Monday, November 22, 2004

Gmail RSS based

(El RSS de Gmail)

Here is the atom file for gmail service https://gmail.google.com/gmail/feed/atom

Enjoy


Permalink: Gmail RSS based 

Thursday, November 18, 2004

Desktop Google AdSense Statistics Application

(Aplicacion de escritorio para estadisticas de Google AdSense)

I have downloaded and install this application. It lets me have my AdSense statistics at my desktop, with a lot of reports and charts. See screenshots

At first sight, there's a little problem with language. You must close and reopen it if you want to have it in English.

It's a Beta, so...


Permalink: Desktop Google AdSense Statistics Application 

Tuesday, November 16, 2004

RFID: A solution to supermarket queues

(RFID: Una solucion para las colas en los supermercados)

In this article Neil Cowburn(an openNetCF) talks about RFID.

IMHO he forgot to talk about the difficult adoption of this for the people, and the problem of what happens with broken or pulled up!!! tags.


Permalink: RFID: A solution to supermarket queues 

Friday, November 05, 2004

Calling doPostBack from a child window for example a popup

(Ejecutar doPostBack desde una ventana hija como por ejemplo un popup)

In web applications you often open a popup with any data which fill some field in the opener window.

For example if you have a field that could have different data depending on the values that you have selected in other fields, you normally will not want to load this data when the page will be loaded. Instead of this, when you are going to fill this field, you open a popup, given it the values of the other fields, and when you select something into the popup you fill the field in the opener and close the popup.

See an example:

I have a textbox named TextBox1 which going to be filled by a link into a popup created using window.open()

In the popup I put the following code:

<a href="#" onclick="window.opener.document.getElementById('TextBox1').value='Filled From Popup';window.opener.__doPostBack('TextBox1','');window.close();">doPostBack and close</a>

When you click in the link you can see that the textbox will be filled with the text Filled From Popup, the doPostBack will be executed, and the popup will be closed.

One reminder: If ASP.Net doesn't create the javascript code for __doPostBack in the opener window, you can force it. See this post


Permalink: Calling doPostBack from a child window for example a popup 

Force ASP.Net to put the __doPostBack client javascript onto the page

(Forzar a ASP.Net a poner el javascript de cliente __doPostBack en una pagina)

Only two HTML form elements (button and image button) cause form postback. If you have a text box, a link button or a custom control that renders an HTML element that does not cause postback, ASP.Net doesn't write __doPostBack javascript client code.

If you want that asp.Net write the client code there's a simple way, put in your code:
Page.GetPostBackClientEvent(LinkButton1, "")


LinkButton1 is the ID of and link button that I have put in my page


Permalink: Force ASP.Net to put the __doPostBack client javascript onto the page 

Thursday, November 04, 2004

SQL Mobile Beta 1 is here

(SQL Mobile Beta 1 esta aqui)

Microsoft SQL Server Mobile Edition (formerly code-named "Laguna"), the next release of SQL Server Windows CE Edition (SQL Server CE), is a mobile database solution designed for developers who target Microsoft Windows mobile-based devices.

New features and enhancements planned for SQL Server Mobile Edition will focus on the following key areas:


- Integration with SQL Server 2005(or 2000), the next release of SQL Server, and Microsoft Visual Studio 2005 (formerly code-named "Whidbey"), the next release of Visual Studio .NET
- Increased reliability and performance
- Faster development of mobile applications
- Column-level tracking:Only the modified columns will be synchronized, not all row
- Row-level locking
-Read more here


SQL Mobile Beta 1 is available with both Microsoft SQL Server 2005 Beta 2 and Microsoft Visual Studio® 2005 Beta 1. Both are only available right now to MSDN Subscribers.

Companies and users of SQL Mobile that plan to synchronize to SQL Server 2000 or SQL Server 2005 Beta 2 databases will need to install Server Tools on their servers running Internet Information Services (IIS).


Permalink: SQL Mobile Beta 1 is here 

Enterprise Mobile Dev point of view from Russell Beattie

(Punto de vista de Russell Beattie sobre los desarrollos moviles empresariales)

As good expert of mobile development Russell Beattie talks about how development tools are more important than the underlying language.

Read the article in his blog


Permalink: Enterprise Mobile Dev point of view from Russell Beattie 

Friday, October 29, 2004

Navigate to a desired URL typing one word in internet explorer

(Navegar a una URL escribiendo una solo palabra con Internet Explorer)

A long time ago I read a trick for internet explorer which avoids me a lot of typing. For example to go to the blogspot page for posting, I type in internet explorer the word post and it sends me to the http://www.blogger.com/app/post.pyra?blogID=XXXXXX. How?

Go to the desired URL, once loaded go to bookmarks and click in Add to bookmarks. In the name, put a single word(in the previous example I put post ). Be sure that the folder selected is Bookmarks(it could be has a start at its left), because the trick doesn't work in subfolders. Click on accept and all is done.

Now you type the word in explorer and it goes to the desired page.


Permalink: Navigate to a desired URL typing one word in internet explorer 

Thursday, October 28, 2004

XHTML FAQ. <img> tag disappears!!!

(Preguntas frecuentes de XHTML. La etiqueta <img> desaparece!!!)

As I can read into this FAQ (Same FAQ in Spanish), provided by the W3C(World Wide Web Consortium) many things about relationships between HTML and XHTML 1.0, why migrate to XHTML, which user agent support it, which mime type you must use, but also I have seen something that I'm surprised that img tag disappears!!! in XHTML 2.0.

The title of the section is Is <img> being replaced by in XHTML?, and the reason is very reasonable. All images are equivalent to some piece of content; If XHTML 2.0 allows you to put a src attribute on any element at all, this says that if the image is available, and the browser can process it, use it, otherwise use the content of the element. For example:

<p src="map.png"><span src="map.gif">Exit from station...</span></p>

Although it is better to use content negotiation if your server supports it (and most do):

<p src="map">Exit from station...</p>

Which would negotiate with the browser which sort of image it accepts, and give the browser its preferred sort. If there is no available image, then the content of the element would be used. This has an added advantage that you can later add other image types on your server and you don't have to change the page for it still to work.

One more thing: Other killed. The term browser, which should be replaced, in most cases by user agent. Just read Why do you say "user agent" everywhere, instead of "browser"?



Permalink: XHTML FAQ. <img> tag disappears!!! 

Google Cheat Sheet. Google search tips

(La chuleta de Google. Trucos para las busquedas)

I have read in Dirson that Google brings its Cheat Sheet.

Some examples:

~auto loan: loan info for both the word auto and its synonyms: truck, car, etc.
red * blue: the words red and blue separated by exactly one word.
[#]…[#]: Search within a range. DVD $100...150(DVDs between $100 and $150)

There are more, let's read and enjoy



Permalink: Google Cheat Sheet. Google search tips 

Tips for Google Desktop Search

(Trucos para el Google Desktop Search)

Via InsideGoogle I found this web page with many interested tips about Google Desktop.

Some of them are:

Some preferences you should set
Move index file to a different drive
Files on Mapped Network Drives
Finding a File by Part of the Name


Have a good desktop search :)


Permalink: Tips for Google Desktop Search 

Wednesday, October 27, 2004

Change the owner of all tables in SQL Server

(Cambiar el propietario de todas las tablas en SQL Server)

Normally you use sp_changeobjectowner(SQL Server 2000 SP3)

Sample:
Remenber to have the right permissions. In this sample I'm running as dbo and i have logged by using sa

use Northwind
EXECUTE sp_changeobjectowner 'EmployeeTerritory', 'guest'

To take back this, the parameters change a little:

use Northwind
EXECUTE sp_changeobjectowner 'guest.EmployeeTerritory', 'dbo'

Well you must do it for all tables, but using an undocumented Stored Procedure called sp_MSforeachtable you can do this in one line of code:

use Northwind
sp_MSforeachtable @command1="sp_changeobjectowner '?', 'dbo'"

Another undocumented Stored Procedure is sp_MSforeachdb which could be used for change the owner of all Databases

Of course among of this use you can manage to make more interesting things mainly if You are a DBA


Another tip: If you are into the Entreprise Manager seen the data in a table and you want to modify a field an insert null in it, put the cursor in it and press CTRL+0 (Control and zero).


Permalink: Change the owner of all tables in SQL Server 

Tuesday, October 26, 2004

Taking the max of AdSense. A little tricks

(Usando AdSense a tope. Unos pequeños trucos)

I have started to put AdSense in my weblog one week ago, and I have started to test something things to taking the max of it.

There are 2 tricks using 2 google web tools:

1- One year ago, when Google created its advertising tool called AdWords, Arcadi show me a web tool provided by Google for knowing how many could cost to You put an advertising in AdWords. You put a word in it and the tool told You how many searches by month it brings and how cost it to You based on cost-per-click(aka: CPC). This tool is only accessible while you are trying to create a new account in AdWords.

It's the "Create Ad Groups", the second step in the process. One recommendation, fill the fields with more or less good things because the wizard check all them very intensively. When you are in the this step there will be a button with the text "Calculate estimates". I tried visual basic as keyword and these are the results:

Keyword-Clicks/Day Average-Cost-Per-Click-Cost Average-Position

visual basic-720.0-0.14 Euros-100.09 Euros-1.3

Overall-720.0-0.14 Euros-100.09 Euros-1.32



The word concordance tool gives You the other searches which people search similar to the word You write. This tool can be tested for many languages and for many countries.

Well, the trick are those tools. Using them, I put a google_hints variable in the AdSense code(You can see it in my weblog code), which right now are google_hints="ado+net,Net,asp+net,asp+net+code,compact+framework,
visual+basic,wifi,bluetooth,mobile,dot+net";

Even It is not permitted by AdSense terms, if You are interested in some of the advertising, just click ;)


Permalink: Taking the max of AdSense. A little tricks 

Saturday, October 23, 2004

Joel Spolsky interviewed at Microsoft Watch. A must read

(Joel Spolsky entrevistado en Microsoft Watch. Hay que leerlo)


Two technology titans face to face talking about Microsoft, Google, etc.


Permalink: Joel Spolsky interviewed at Microsoft Watch. A must read 

Get WIFI Adapters signal strength

(Obtener la intensidad de señal de los tarjetas WIFI)


If you want to know if your wifi adapter is in the range of any wifi net(do not do it for making an wifi scanner to warchalk or something else... remember, this code is only for research projects, bla bla bla)

First of all add a reference to System.Management.dll and then an Imports System.Management

Public Function GetSignalStrength() As String
Try
Dim Oq As ObjectQuery = New ObjectQuery("SELECT * FROM MSNdis_80211_ReceivedSignalStrength Where active=true")
Dim Ms As ManagementScope = New ManagementScope("root\wmi")
Dim query As ManagementObjectSearcher = New ManagementObjectSearcher(Ms, Oq)
Dim outp As String = ""
For Each Mo As ManagementObject In query.Get
If CType(Mo("Active"), Boolean) = True Then
outp &= CType(Mo("Ndis80211ReceivedSignalStrength"), String) + Environment.NewLine
End If
Next
If outp = "" Then outp = "There isn't any WIFI adapter active"
Return Trim(outp)
Catch e As Exception
Return e.Message
End Try
End Function




Permalink: Get WIFI Adapters signal strength 

Friday, October 22, 2004

v2.0 Select Random Rows from MS Access

(v2.0 Seleccionar filas aleatoriamente en MS Access)

Adding in the query "ORDER BY Rnd(filedName)" or with code


Dim adapter As New OleDbDataAdapter("SELECT * from myTable", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Web.HttpContext.Current.Request.MapPath("data.mdb") + ";")
Dim data As New DataSet
adapter.Fill(data)
Dim table As DataTable = data.Tables(0)
If table.Rows.Count = 0 Then
Throw New Exception("The query return 0 rows")
End If
Dim Random As New Random(System.DateTime.Now.Millisecond)
'first column of the random row
Dim sResult As String = table.Rows(Random.Next(0, table.Rows.Count)).Item(0).ToString()


Thanks Arcadi



Permalink: v2.0 Select Random Rows from MS Access  

Select Random Rows from MS Access

(Seleccionar filas aleatoriamente en MS Access)

Usually you have to take a random row from an Access DB, the following code makes it.

Tip: If You're accesing Access in a web (.aspx page, web service) You need remenber that ASPnet user must have full access(read, create, delete, modify) to the folder where the mdb lies, because it has to modify the .mdb file and create/deltete the .ldb file.

Added: Better code in v2.0 Select Random Rows from MS Access


Dim adapter As New OleDbDataAdapter("SELECT * from myTable", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Web.HttpContext.Current.Request.MapPath("data.mdb") + ";")

Dim data As New DataSet
adapter.Fill(data)
Dim table As DataTable = data.Tables(0)
If table.Rows.Count = 0 Then
Throw New Exception("The query return 0 rows")
End If
table.Columns.Add("Random", GetType(Double))
Dim random As New Random
For Each row As DataRow In table.Rows
row("Random") = random.NextDouble
Next

Dim dv As DataView = table.DefaultView
dv.Sort = "Random ASC"
Dim sResult As String

'the first column
sResult = dv.Item(0).Row(0).ToString()




Permalink: Select Random Rows from MS Access 

Wednesday, October 20, 2004

Extend Bluetooth coverage on a USB Bluetooth adapter(aka:dongle)

(Ampliar la covertura bluetooth de un adaptador USB(conocido como dongle))

Via blueseeker I found this interested article talking about USB coverage

Enlarge this image




Permalink: Extend Bluetooth coverage on a USB Bluetooth adapter(aka:dongle) 

A critical point of view of Google Desktop

(Una vision critica del Google Desktop)

This post has a very critical point of view of Google Desktop, by the microsoftie Franci Penov.

"1-It hooks up WinInet.dll. Hooking up system level component and intercepting all incoming/outgoing traffic on my machine has nothing to do with my desktop search. (Btw, it's amazing how many antivirus programs Google Desktop is incompatible with because of this)
2-...."

Let's read all his conclusions and take your owns.

Other good article of Google Desktop at Infoworld


Permalink: A critical point of view of Google Desktop 

Bill Gates and his optimism for the future of computing

(Billl Gates y su optimismo sobre el futuro de la informatica)

Here You can find and article written by Bill Gates talking about his ideas about the future/present of computing.

The title of the article is "My optimism for the future of computing has never been greater".

Let's read...


Permalink: Bill Gates and his optimism for the future of computing  

Tuesday, October 19, 2004

Avoid doPostBack and trap the caller object

(Evitar doPostBack y obtener el objeto que lo llama)

Sometimes you want to avoid the execution of the doPostBack, or make something before the doPostBack will be executed.

The following snippet do that. First We replace the __doPostBack with another variable called newPostBack, and maintain the old in another variable called oldPostBack.
When any object calls doPostBack, the function that will be executed will be newPostBack. In newPostBack function We can trap the caller object into the parameter eventTarget.
The ID of the object is btnDoit, and We get its outerHTML and do not execute the doPostBack.
If another object calls the doPostBack it will be executed normally.


<script id="anti_doPostBack" language="javascript">
<!--
// Replace the postback
oldPostBack = __doPostBack;
__doPostBack = newPostBack;

var oldPostBack

function newPostBack(eventTarget, eventArgument) {
if (eventTarget == "btnDoit") {
alert(document.getElementById('btnDoit').outerHTML);
} else {
//If the call to __doPostBack was NOT from btnDoit,
//then call the original __doPostBack.
oldPostBack(eventTarget, eventArgument);
}
}
//-->
</script>



Permalink: Avoid doPostBack and trap the caller object 

Export datagrid to Excel

(Exportar un datagrid a Excel)

Usually I have to export reports to Excel. The most common way is make a web page which put the excel mime type and sends the report table

Response.ContentType = "application/vnd.ms-excel"
Response.Write(sReportTable)


If the reports are only queries to the database, is very simple, because you only have to pass the query to the page, but if you have to make some calculations you have to put the code in the page.

The solution is getting the outerHTML of the datagrid(DataGrid1 is the ID of the datagrid object in my .aspx page) and putting it in the clipboard. How?


<a href="#" onclick="var ret;ret = window.clipboardData.setData('Text',document.getElementById('DataGrid1').outerHTML);if(ret){alert('Copy OK');}else{alert('Copy failed');}">Copy</a>


Just open Excel an Edit-Paste


Permalink: Export datagrid to Excel 

Saturday, October 16, 2004

Openwave Supports I-Mode in Europe

(Openwave soportara imode en Europa)

An agreement between NTT DoCoMo and Openwave had been sign for supporting this technology in all products of Openwave(servers and clients)

Today 51 mobile device manufacturers license the Openwave Mobile Browser, which has shipped in more than 600 million handsets and supports mobile phone networks in use around the world, including WCMDA, CDMA, GSM, TDMA, iDEN, PHS, and PDC.

The Openwave notice

As I can understand(with my more than 5 years old experience in mobility), imode hasn't any sense, but Openwave have taken her decision. Perhaps NTT Docomo has given enough money to Openwave.

Imode as a language(real cHTML) will lose the battle with a more standardized XHTML(Visual Studio .Net 2005 write it as default markup language). Imode as a platform will lose the battle with the phones which use standard internet.



Permalink: Openwave Supports I-Mode in Europe 

Wednesday, October 13, 2004

PalmOne licenses Microsoft Exchange for mobile e-mail

(PalmOne licencia Microsoft Exchange para email movil)

As You can read at Infoworld the first PalmOne device to include the Microsoft technology will be a new Treo smart phone. The Microsoft's Exchange Server ActiveSync protocol, allow users of PalmOne devices will no longer need to install third-party client and server software to be able to access e-mail, calendar and contact information on a server running Microsoft's Exchange Server 2003 software.

More on Microsoft Press


Permalink: PalmOne licenses Microsoft Exchange for mobile e-mail 

Friday, October 08, 2004

Old bugs in new software. Successful proof of concept!

(Viejos agujeros en el nuevo software. Prueba de concepto exitosa!)

While I'm reading blogs I've found the proof of concept of the bug in canonicalization of the URLs.

In my machine the bug works so it's time to patch it with the method 2

A standard forms authentication setup requires the presence of "web.config" to set the authentication method and login procedure. The presence of this file prevents access to certain files (.aspx files for example) unless authenticated.
Put in web.config

<authentication mode="Forms">
<forms name=".FORM" loginurl="login.aspx">
</authentication>

--- Example ---
The webroot for your website is:
c:\inetpub\wwwroot\mysite
You want to secure files in a sub directory "secure"
c:\inetpub\wwwroot\mysite\secure\web.config
A request to http://localhost/secure/somefile.aspx would then redirect the user to a predefined authentication page(login.aspx), as defined in web.config, before allowing the user access to "somefile.aspx".

--- Bug ---
1. Using Mozilla not IE, you make a request to http://localhost/secure\somefile.aspx The use of a backslash rather than a forward slash appears to bypass the expected authentication model invoked in .NET forms authentication
2. Using IE, you make a request to http://localhost/secure\somefile.aspx - IE automatically replaces the backslash "\" with a forward slash "/" and everything appears fine. However, replace the backslash "\" with %5C (%5C being hex value for \) and all is not so fine:
http://localhost/secure%5Csomefile.aspx



Permalink: Old bugs in new software. Successful proof of concept! 

Running multiple versions of .Net Framework(aka:Side-by-Side Execution)

(Usando varias versiones del .Net Framework(Conocido como Side-by-Side Execution))

Three weeks ago I put my hands on .Net Framework 2.o Beta, and I found the problem that my ASP.Net applications compiled under version 1.0 and 1.1 fail. As I usually do on this cases I made a search in google with this text Running multiple versions of .Net Framework and I found the problem quickly.

This page gave me the solution. The problem was that when I installed the new version of framework it registered this version for all sites in the IIS.

The solution is re-register those sites with the correct version. It can be done with the command line ASP.NET IIS Registration Tool (Aspnet_regiis.exe), provided with the framework.

For the very lazy people exits a GUI implementation ASP.NET Version Switcher

Screenshot of ASP.NET Version Switcher
ASP.NET Version Switcher



Permalink: Running multiple versions of .Net Framework(aka:Side-by-Side Execution) 

Old bugs in new software. Solution 2

(Viejos agujeros en el nuevo software. Solucion 2)

This is a trick that Web site administrators can apply to their Web server to protect it from the bug in canonicalization of the URLs.

Microsoft has released an ASP.NET HTTP module that you can download at http://www.microsoft.com/downloads/details.aspx?familyid=DA77B852-DFA0-4631-AAF9-8BCC6C743026&displaylang=en.

Enjoy and pray. Another bug could be waiting for you Out There


Permalink: Old bugs in new software. Solution 2 

Thursday, October 07, 2004

Old bugs in new software

(Viejos agujeros en el nuevo software)

Upss..., it isn't official, but could be a bug in ASP.Net which let users read authorized files through a problem in canonicalization of the URLs.(The article is in http://www.microsoft.com/security/incident/aspnet.mspx)

The "Programmatically check for canonicalization issues with ASP.NET" article gives you a explanation and a solution?¿ for this problem, but I post here the code for vb and C#.

Put in the Application_BeginRequest event handler of the Global.asax file.

Visual Basic .NET

<script language="vb" runat="server">
  Sub Application_BeginRequest(Sender as Object, E as EventArgs)
    If (Request.Path.IndexOf(chr(92)) >= 0 OR System.IO.Path.GetFullPath Request.PhysicalPath) <> Request.PhysicalPath) then
      Throw New HttpException(404, "Not Found")
    End If
  End Sub
</script>


C#

<script language="C#" runat="server">
  void Application_BeginRequest(object source, EventArgs e){
    if (Request.Path.IndexOf('\\') >= 0 System.IO.Path.GetFullPath(Request.PhysicalPath) != Request.PhysicalPath) {
      throw new HttpException(404, "not found");
    }
  }
</script>



Permalink: Old bugs in new software 

3,2,1 Go

3,2,1 Despegue

Well, this is my first post, and I'm sure that only friends going to read this post, but it doesn't matter ;)

The main reason of this blog is to be a share point for interchange impressions about mobility and about .NET development.(but this is not an obstacle for speaking about another things).


Permalink: 3,2,1 Go