Thursday, November 19, 2009

Sql server getdate() – set to midnight

a very short note on a particular use of getdate() to obtain the today’s date with hours minutes and seconds set to midnight (00:00:00):

select dateadd(day, datediff(day, 0, getdate()), 0)

Friday, November 13, 2009

Facebook – wall post with Facebook Developer Toolkit, stream.publish

Just a c# sample that I find useful to have here – so that everybody around me can find it whenever needed :-)

public void Post(facebook.API fbAPI, string appLink)
{
    string response = fbAPI.stream.publish(
        " decided to go nuts.",
        new attachment()
        {
            name = "my application rocks",
            href = appLink,
            caption = "{*actor*}decided to go nuts.",
            description = "One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin. http://indialimaalpha.blogspot.com/
",
            properties = new attachment_property()
            {
                category = new attachment_category() { text = "Take another action...", href = appLink }
            },
            media = new List<attachment_media>() {
                new attachment_media_image() { src = WebConfigurationManager.AppSettings["AbsolutePath"] + "images/go_joseki.jpg", href = appLink }
            }
        },
        new List<action_link>() {
            new action_link() { text = "Take Action!", href = appLink }
        },
        null,
        0);
}

Friday, November 06, 2009

Sql Server Restore

 

Some statements I found useful to recover a database backup applying some transaction logs (had to step into this due to a wrong delete operation on a production database – no, it wasn’t me…).

RESTORE DATABASE [TheDatabase]
FROM DISK = 'D:\foldername\bak\FULL_20091102_024436.bak'
WITH
MOVE 'TheDatabase_Data' TO 'D:\Program Files\Microsoft SQL Server\MSSQL\Data\TheDatabase_Data.mdf',
MOVE 'TheDatabase_log' TO 'D:\Program Files\Microsoft SQL Server\MSSQL\Data\TheDatabase_Log.ldf',
NORECOVERY

RESTORE LOG [TheDatabase] FROM DISK = 'D:\foldername\bak\20091102_060214.bak' WITH NORECOVERY

RESTORE LOG [TheDatabase] FROM DISK = 'D:\foldername\bak\20091103_180221.bak' WITH NORECOVERY

[…]

RESTORE LOG [TheDatabase] FROM DISK = 'D:\foldername\bak\20091105_000219.bak' WITH NORECOVERY

RESTORE LOG [TheDatabase] FROM DISK = 'D:\foldername\bak\20091105_060204.bak' WITH RECOVERY

Some comments: the NORECOVERY option used in all the statement but one causes Sql Server to leave the db in a non operational state; this is needed because we will apply other restore statements. In the last one I use the RECOVERY option, in order to put the database in operational state.

Obviously this is only a little part of the big big world of database maintenance: just to say, give a look at the RESTORE command syntax… http://msdn.microsoft.com/en-us/library/ms186858.aspx

Bye!

Sunday, October 25, 2009

Azure Sql Services – let’s try!

I decided to ask for a test account in the preview phase of Azure sql services, and today I’m trying to connect to it.

The signup process is quite easy and simple; once logged, I reach the web administration console for my databases.

I created my first db, 1gb maximum size. Now I want to connect to it using SSMS (Sql Server Management Studio) from my laptop. In the console there is a useful link to ready made “connection strings”, I use them to fill the SSMS connection dialog – but hey! I cannot connect…

After some clicking around I notice that I can setup the “firewall rules” in order to gain access from my IP. Let’s try.

The connection error actually states that I cannot connect from 78.14.234.1, so I fill the form to setup a “grant access” rule, as in the screenshot below:

Now I can connect successfully! And I can launch a New Query against my db, and run some (useless, I know) statements like:

The statements are quite silly, just to prove that I can do DDL.

Now I see that I cannot use the SSMS native “Object Explorer”, and looks like it’s impossible.

Looks like there are some alternative tool in this field, with some limitation (it’s a brave new world…); for example http://hanssens.org/tools/sqlazuremanager/ – Sql Azure Manager; is a tool developed to connect to Azure. It’s a ClickOnce setup, around 3.76 Mb in size. Once downloaded and installed, it prompts for your database connection parameter and you’re in.

There is also a web-based tool, Omega.MSSQL, at https://onlinedemo.cerebrata.com/SQLAzureClient/default.aspx. I cannot connect through this, but I found good opinions on it, so maybe it’s a problem on my side.

Another tool: “Gem Query Tool for Sql Azure”, here: http://microguru.com/gem/ – it’s very simple and lacks a lot of features… but again, I think that all these tools are too young to tell.

So far so good. I’ll keep you informed on this subject as I understand better. Bye!

Sunday, September 27, 2009

Windows Mobile Device Cannot Connect (or Quickly Disconnect or Drop) and Not Sync with Vista WMDC (ActiveSync)

Sometimes my Wondows Mobile phone stops syncing with the laptop, and I always go nut trying to discover the reason of this behavior.

Today while searching on Bing I found a page that shows  the solution in a very clear way, and here is the link to that:

Windows Mobile device cannot connect or quickly disconnect

Happy syncing!

Thursday, September 24, 2009

.net, accessing web services test form

I know, this is a trivial thing for you all… but I still have problems in remembering, so I’ll note here this little snippet.

To enable the web service test form (that you can access only if call the web service in localhost) you will have to add to your web config these lines:

    <system.web>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>

Windows 7 new shortcuts, very useful

New and absolutely useful shortcuts on Win7, thanks Claudio for showing me.

- WinKey + direction keys: moves around the top window (the one that has focus). If you press WinKey + up arrow, the window will bw maximized. Guess what the WinKey + down arrow dows?

- WinKey + shift + left or right keys: moves the current window on the corresponding screen if using more than one (why, are you still developing on a single monitor setup?)

- In Explorer windows, try Shift + Ctrl + n. Ok, I waited for this almost ten years…

Bye!

ila

Wednesday, September 16, 2009

Project Euler and Algorithmatic

I registered on Project Euler and Algorithmatic.com, and found this synergy: I uploaded my solution to http://projecteuler.net/ first problem on algorithmatic.com here: http://www.algorithmatic.com/algorithm/31/version-1/project-euler-1/