Categories
Geeky/Programming

.NET and Oracle – Match Made in Hell (Data provider internal error(-3000) [System.String])

At my new gig, I am working on a project that is ASP.NET with an Oracle Database backend. Today I ran into an error.

Data provider internal error(-3000) [System.String]

What does this error mean? Heck if I know, its a generic error basically telling you that something is wrong with your connection to the database more than likely.

After troubleshooting code, the CSLA framework, more code, stored procs, queries, more code and testing everything I could think of, I decided it had to be something with the Oracle driver on my machine. I remembered back in the day when I worked for SCWH using Oracle 8 and having a hell of a time getting it to work if the driver was even a .1 release off, or if you were using the wrong driver.

Reinstalled the 10g client and Oracle Data Provider for .NET stuff and it worked. What a waste of time. Just another reason why I hate Oracle, and SQL Server is the way to go. No stupid dot releases of drivers that cause headaches. Granted MSFT used to have MDAC which was a major pain, but with .NET it just connects, and works.

Categories
Geeky/Programming Ramblings

A Good Memory Is A Great Thing To Have

Well, I haven’t posted in a while. Still busy as ever. Was up north for the 4th and my 10 Year reunion. Pics are on Flickr.

Anyways, this post is about a “Good Memory”, or even better, the ability to memorize things. Memorization.

So what does memorization have to do with anything? Well, as far as computer stuff goes, programming, development, database stuff, networking, sysadmin, all aspects, even just regular old users using their computers. Memory (not RAM), but remembering how to do things is going to make you better. Not just better, but substantially better.

Remembering things will probably make you a very good developer. How? You won’t have to keep looking things up. It should start out with you remembering the syntax of the language you are using. Then comes remembering how to setup and tweak your tools (IDE), then comes remembering different concepts (loops, OOP patterns, etc). Next comes remember old code you wrote to solve some problem, and going back to it and using it again. This is just the tip of the iceberg.

As any good developer should, you should be able to remember how to use the OS and tools you are using. If you can’t even do that, you probably shouldn’t be developing software. A simple example, like setting up a printer in Windows XP, or pinging Google, or using CTRL+C and CTRL+V – these simple concepts are going to make you a better computer user, not just a developer. There is no excuse for not knowing these simple things!

Now, if you can remember tons of little things like that, and then start adding in Framework libs, and IDE tricks and how the network works, or every other nugget of info you should be remembering. You might not remember every blog or site bookmark full content, but you should remember that you bookmarked it and why. Just little things.

Another area where memorization is key is with music. Playing music. Singing music. Take playing guitar or piano for instance. You can read off the music time and time again, but you are using part of your brain on that, not focusing on actually playing. Once you memorize the music, you can play it better, and focus on actually playing, not where you are on the music page.

Same thing with looking up things in help or guides for development. If you keep having to look up DATEDIFF in SQL books online, you are just wasting time. Learn how it works, learn the params and what they are, and memorize it.

I think the only time you should be using the help is to search for something that you haven’t memorized. Like, “I wonder if there is a C# function to do XYZ”. Then, you search help, even better Google, or ask someone who you think might know. But you shouldn’t have to Google or ask someone “Hey, do you know I set up a FOR loop?” – That you should know, and have memorized (plus a ton of other things!!)

The more you memorize, the better you will become, because you can focus on the problems to solve, not learning the tools and concepts you should already know. Oh, and you can play some wicked guitar as well 🙂

Categories
Business Intelligence Geeky/Programming SQLServerPedia Syndication

SQL Server Reporting Services: Quick way to get 10 digit year (all the zero's) using String.Format

Dates are fun. See, by default most dates come out like 5/6/2008. But computers, and programs like them formatted as 05/06/2008. That way, all the dates, no matter what month or day, are all the same length, cool huh?

Well, in Reporting Services, if you have a date field coming back in a dataset, and you want to format it as a 10 digit string, there are about 50 different ways to do it. You can use old VBA Left and Mid etc, or you can use String.Format like..

=String.Format(“{0:MM}/{0:dd}/{0:yyyy}”,CDate(Fields!CalendarDate.Value))

Categories
Geeky/Programming Ramblings

Hacking Microsoft Pro Photo Tools – Using Reflector to use MapPoint Lat Long Lookup (for free!) in C#

The other day, Microsoft came out with “Microsoft Pro Photo Tools” which allows you to geocode your photos. It is a pretty cool app, but there are some things that I wonder, like why didn’t they just build this functionality into Windows Live Photo Gallery?

Anyway’s, with any new thing I download and play around with, I started digging into stuff. I looked in the install directory, C:Program FilesMicrosoft Pro Photo Tools and noticed that there are some Interop assemblies and other assemblies, etc. I fired up Reflector and started disassembling the assemblies and exe. Pretty cool stuff, you can see what they are doing. Using xaml forms, etc. The cool stuff is the Location based stuff.

Microsoft has MapPoint web services which you can use/sign up for, but they cost a pretty penny. I have used some of these web services in the past and they have a ton of functionality.

Like I said, digging through the disassembled stuff in Reflector, I saw a method “GetLatitudeLongitude()” which takes in country, state, city, address, zip and returns a lat long object. But, you need a “MapPointWrapper” object to use it.

I fired up Visual Studio 2008, and then referenced the assemblies in the Pro Photo Tools directory so I could use them in code. I created a test WinForms app, and started hacking away.

Looking at the MapPointWrapper class constructor in Reflector, I noticed that it needs a username, password, URL, and timeout, the first three I don’t have – but I bet I could find!!

Here you can see the constructor as it looks in Reflector. The thing I noticed right away is that they have the username and password embedded in the function, although its all “encoded”, then blend the strings together to create default credentials. Their blend method is using some bitwise operators, etc, if you are interested, you can just click on the Blend method and it browses to that (did I mention Reflector is cool??) – anyway’s, I still need a URL…

image

Reflector lets you click on a class and “analyze” it, which gives you what classed depend on it, which classes use it etc. Just going through the list for MapPointWrapper, I found one that showed how they call the constructor.

image

That’s the ticket! You can see they are passing in empty strings for user/pass (which then gets converted to the correct user/pass by the constructor) and then the URL is right there!!! nice! We can use this!!

Now, on to using this functionality in our own app!!

image

Now, this will give you the lat/long back from MapPoint! Sweet. Now we can start digging into everything else – what else do these assemblies expose?? Can I get routes? directions? Maps? etc, etc, etc. There is a plethora of things to dig into. It looks like they are just using Virtual Earth though to get maps, not MapPoint (from what I can tell anyways).

I know there are a ton of other ways to get this info, but this was basically a test to reverse engineer their assemblies and use the functionality. I don’t recommend or condone hacking/reverse engineering assemblies like this for profit, more for fun , in other words – don’t use this in a production app as Microsoft would probably find out and come hunt you down.

This post is also just an example of how .NET code can be disassembled easily and re-used, for good, or evil 🙂

There are some basic things that every developer should do with .NET desktop apps – use Dotfuscator (which just obfuscates your code, making it harder/not feasible to reverse engineer, and also encrypt any strings/values you don’t want anyone else using or reading. That being said, Reflector is a great way to see how other applications are coded, and learn how they work. Happy Coding Hacking!

Categories
Geeky/Programming

Auto Submit Form in ASP.NET With Javascript

Not sure if this is the best way to do this, but this is what I do. Say you want to auto submit a form on an aspx page. You can call document.formname.submit(); from the body onLoad event and it will submit, but ASP.net will automatically post it back to itself.

I tried added buttons with different postbackUrl’s, clicking the submit button in javascript, etc to no avail.

First, what I had to do was put on my ASP Classic hat. Look at your <form> and remove the runat=”server”

Then, you can say document.formname.submit(); and it will submit your form.

How do you pass data though?

Well, you have to created input fields, probably hidden like

<input type=”hidden” name=”blah” id=”blah” value=”<%= Request.QueryString[“myvalue”] %>” />

Then you can pass data from another page or whatever and auto submit your form.

It would be nice if you could say in your Page_Load() something like

 

btnSubmit.Click(); and it would automatically click it and submit your form, but that doesn’t seem to be available at all.

Like I said, there is probably a better way to do this, and it shouldn’t be this complicated, but a few minutes googling for answers left me up in the air. Funny how something that is so easy in ASP Classic turns out to be harder in ASP.NET. ASP.NET wants you to really post back to the same page by default. It hijacks the “action” attribute on the form no matter what with runat=”server on there.

Categories
Geeky/Programming

Ruby on Rails and MySql .. on Windows Vista

So, this evening I got the urge to get Ruby on Rails working on Vista, with MySql. I haven’t done much with RoR, but figured I would give it a go. I have this test hosting account that has RoR hosting, so that is what got me somewhat motivated…anyway’s, on with the show.

 

Install Ruby

Installing Ruby is pretty easy. You can follow the tutorial pretty much step by step from the rubyonrails.org site, except it is tailored to *nix machines (Mac, Linux) as far as paths and stuff..

1) Download and install ruby..(http://www.rubyonrails.org/down)

2) get RubyGems, run ruby setup.rb

3) Get rails:…. gem install rails –include-dependencies

Create Application

At the command prompt:

rails c:railsblog

cd railsblog

ruby script/server

test it on http://localhost:3000

if all is well, you will see a cool welcome screen..

Now.. lets actually start making our blog app by generating a controller..(remember , you need to call “ruby” before executing these scripts.. in Mac, etc you don’t have to)

ruby script/generate controller Blog

Then edit your blog_controller.rb and add some code:

class BlogController < ApplicationController
    def index
        render :text => “Hello World!”
    end
end

try it (http://localhost:3000/blog).. whoops.. error?

no such file to load — sqlite3

check under your app dir (c:railsblog) your configdatabase.yml

it is set to sqllite.. we need to get MySql installed and configured

Install MySql (5.0.51a)

This is a whole nother debacle. MySql doesn’t really work right on Vista.

download MySql (http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-essential-5.0.51a-win32.msi/from/pick#mirrors), install it

you will notice.. the config assistant doesn’t run at the end..

Configure It, Hack It, Swear At It

First, in the MySql/bin directory, set both the MySql config assistant and the mysqld-nt.exe to run in XP Sp2 compatibility mode, and run as administrator (this will
allow the service to start once the config assistant is done, once we hack to run anyway’s)

In your application logs in event viewer you will see

Activation context generation failed for “C:Program FilesMySQLMySQL Server 5.0binMySQLInstanceConfig.exe”.
Error in manifest or policy file “C:Program FilesMySQLMySQL Server 5.0binMySQLInstanceConfig.exe” on line 6.
The value “asAdministrator” of attribute “level” in element “urn:schemas-microsoft-com:asm.v1^requestedPrivileges” is invalid.

Nice..

I guess older version work, but 5.0.51a doesn’t. You can see in the error, “asAdminstrator”, it should be “requireAdministrator”, we need to hack the exe..

download resource hacker – http://www.angusj.com/resourcehacker/

Open the MySqlInstanceConfig.exe in Reshack, ctrl+f, search for “asAdministrator”, change to “requireAdministrator” save and compile the exe over the old one..

Whoo hoo! The config assistant runs!

Basically the defaults, except I chose

“multilingual” on the character set screen,

and checked the “Include Bin Directory in Windows PATH” box on the Windows Options Screen

and – setup a root password on the security screen!

after it is all done, I like to secure my local machine, go to the my.ini in your MySql directory, and under the [mysqld] add

bind-address=127.0.0.1

so only local apps can connect..

Test MySql by opening a cmd prompt,

mysql -h localhost -u root -p

hit enter, it will ask for a password , and you should be able to login

Configure MySql For Our App

login to MySql using the cmd above..then

CREATE DATABASE blog;
CREATE USER ‘blog’@’localhost’ IDENTIFIED BY ‘blog’;
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER ON blog.* TO ‘blog’@’localhost’;
FLUSH PRIVILEGES;

quit

Now we have a database called “blog” a user called “blog” with password “blog”

We need to tie Ruby to MySql now…

run..

gem install mysql

now, you probably have your mysql directory in your path, but since you need to restart your machine or explorer for new paths to show up, it doesn’t work yet..
so we need to make sure we do that, otherwise, if you try hitting http://localhost:3000/blog you will get a libmysql.dll error popup. I just killed explorer.exe and
start->run explorer in task manager, and then hit http://localhost:3000/blog again and saw the “hello world”

Yesssss… it works. Now , for the fun stuff, actually coding and creating tables, and more!!!!

Categories
Geeky/Programming

OAuth: Getting Started with OAuth in C#, .NET

I have been playing around with Pownce and their API. They offer HTTP Basic Authentication and OAuth authentication. I decided to give a go with OAuth since BASIC auth just seems, dirty insecure to me. I started digging around, and http://oauth.net/ has some good info. Under code there is a C# (CSharp) version – http://oauth.googlecode.com/svn/code/csharp/  but, I couldn’t find any good examples of getting started implementing this in your app, so…

I downloaded the OAuthBase.cs class and added it to a sample project so I could get going. Now, how to use this OAuth thing…

Well, first you need a “request token” server/url that you can use, something that takes your request and gives back a token (You can use http://term.ie/oauth/example/ to test, instead of Pownce  or some other utility)

As the “consumer” of the service, you have a key and a secret. The hardest part of the OAuth request is generating the signature, which the OAuthBase.cs does for you. I did run into some small issue with generating a timestamp though, seems that the OAuthBase.cs class had/has a bug in the timestamp function. it was returning back a timestamp like 12393923423.134  instead of just 12393923423 – which the first one, with the .134 will cause an invalid signature in your requests.

I sent a comment/message to the creator of OAuthBase.cs about it, not sure what else to do there, I am pretty sure I had the latest version (it was linked off oauth.net)

here is the function I changed:

public virtual string GenerateTimeStamp() {
    // Default implementation of UNIX time of the current UTC time
    TimeSpan ts = DateTime.UtcNow – new DateTime(1970, 1, 1, 0, 0, 0, 0);
    string timeStamp = ts.TotalSeconds.ToString();
    timeStamp = timeStamp.Substring(0, timeStamp.IndexOf(“.”));
    return timeStamp;           
}

Now, you want to test this out, create a test .NET app (C#), and add OAuthBase.cs to your project. I created a test Windows Form app. I had to add a reference to System.Web as well., then the basic code (I am using the test OAuth server)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Web;
using OAuth;

namespace PownceTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            string consumerKey = “key”;
            string consumerSecret = “secret”;
            Uri uri = new Uri(“http://term.ie/oauth/example/request_token.php”);

            OAuthBase oAuth = new OAuthBase();
            string nonce = oAuth.GenerateNonce();
            string timeStamp = oAuth.GenerateTimeStamp();
            string sig = oAuth.GenerateSignature(uri,
                consumerKey, consumerSecret, 
                string.Empty, string.Empty,
                “GET”, timeStamp, nonce,
                OAuthBase.SignatureTypes.HMACSHA1);

            sig = HttpUtility.UrlEncode(sig);

            StringBuilder sb = new StringBuilder(uri.ToString());
            sb.AppendFormat(“?oauth_consumer_key={0}&”, consumerKey);
            sb.AppendFormat(“oauth_nonce={0}&”, nonce);
            sb.AppendFormat(“oauth_timestamp={0}&”, timeStamp);
            sb.AppendFormat(“oauth_signature_method={0}&”, “HMAC-SHA1”);
            sb.AppendFormat(“oauth_version={0}&”, “1.0”);
            sb.AppendFormat(“oauth_signature={0}”, sig);

            System.Diagnostics.Debug.WriteLine(sb.ToString());

        }
    }
}

 

If you run that app, you will get a debug line like..

http://term.ie/oauth/example/request_token.php?oauth_consumer_key=key&oauth_nonce=1901809&oauth_timestamp=1208645244&oauth_signature_method=HMAC-SHA1&oauth_version=1.0&oauth_signature=iv%2b45QPR9a%2fMDjw8qkEee61Fp0g%3d

One thing that had me scratching my head of a second was my signature was good like 80% of the time, I noticed I wasn’t URLEncoding it, so spaces were getting sent as ( ) instead of (+) – doh!

If you click on the link that is generated, you will get a response like

oauth_token=requestkey&oauth_token_secret=requestsecret

We are good to go! This is just the first step. We need to use those tokens now to move on, but we got past the first step of authenticating to the OAuth server to get tokens! Yay! (Ex: your app has to actually request that url, use the tokens, have the user authorize your app, then go from there..)

This maybe the first in a few blog posts on OAuth – happy coding!

Categories
Geeky/Programming Ramblings

Why is MFC Not Dead?

I was reading through some blogs this morning, and ran across this one, from my MSDN Feed.

Here is my answer (I wanted to leave a comment, but it wasn’t working, and I figured it would be a good blog post anyways)

Right now you can make an MFC app and it can run on win98,2k,xp,vista, etc – out of the box. Anything with .NET requires the framework, and if you want your app to just be downloaded and ran, then the framework limitation hurts you. Why make someone download and install a d 20+ MB framework?

I wish there was a way to deploy .net apps without the framework, maybe with just assemblies the apps needs.

But like I said, companies want apps to run on as many clients as possible, which just isn’t a reality with .NET, but it is with MFC.

I really think Microsoft is clueless on why people use MFC and not .NET or even an Web App. Finally, MSFT is starting to use .NET in their client apps here and there (WLW, SSMS, Zune, etc, etc)

Once all apps written by Microsoft use some form of .NET, and Windows 98, 2000, and XP are gone for good (or at such small % of market share they don’t matter, say < 1%), then we can actually write .NET client applications (and have to target the version of .NET on Vista, since that is the lowest common denominator) – OR… MSFT could push .NET as a critical update to XP and wipe the % of .NET installed down to a low enough number to make it feasible to create .NET client apps and get a good chunk of the market share..

There are always going to be people that use MFC for whatever reason, but ease of use is certianly not one of them. A small example is, in .NET, I can create an app that displays a toast message, has a systray icon, connects to FTP, handles web services, and much much more, in very little time, and with a small number of lines of code, whereas in MFC, doing those things is a huge undertaking, 1000's of lines of code, and even then some of it is very "hackish". Yes, doable, but not very easily.

Another argument could be as well, that if your app is good enough, people will download it and install the framework if they don't have it, and I think that is a very good argument (except windows 98 is out of luck – can't install .NET) – I think this last argument is the best – if people want it, and it is an awesome app, they will install whatever to get it to run.

Anyways, I am rambling.. probably could keep talking on this topic for another 100 paragraphs or so. 🙂

Categories
Geeky/Programming Ramblings

Windows Live Writer – API Open (not really) – I Want To Download Existing Posts

So, I am sitting here scratching my head again. I use Windows Live Writer (WLW) to post to my blog. I like it, it rocks. There is a plugin architecture, which is cool, and some other API’s for doing things.

WLW saves drafts and posted posts as .wpost files to a directory in your My Documents. The files are in a proprietary binary format. It is cool though as all your posts are saved and you can open existing ones, edit, and republish easily.

I want to go through my posts and add WordPress tags. Not technorati tags, but WordPress tags, so I can have a cool little tag cloud. WP 2.5 support WLW tags by default, WP 2.3 (which I am running) can get tags from WLW through a little REG hack which I have applied and it works for new posts.

What I want to do, is update all my historical posts through WLW instead of WordPress web interface.

Since I have reformatted, changed computers, started blogging before WLW came about, of course I don’t have all my posts on this machine. So I thought, why not download them from my blog and create .wpost files so I have them?

First I looked for a plugin, no dice, doesn’t even seem that anyone has wanted to do this. I searched forums, blogs, Google, whatever. Found little info.

Next I dug into the API, nothing there that would really help me. What I would do is just access my posts through the XML-RPC interface WordPress has and create new .wpost files in my directory, you wouldn’t think it would be that tough..but it is.

It would be nice if the .wpost file was open and had a documented spec, that way I could do it easy as 1,2,3. Even if there was some API with WLW to create new posts and save them (you can create new posts, but only by programmatically opening WLW).

Well, I guess I will keep my eyes open for anything that comes along that will make this possible, until then, it is using the WP web interface. I suppose I could write an app to just directly edit the post tags through the XML-RPC API, and save them, but I want them on my machine as well. Just another good backup I suppose.

Categories
Geeky/Programming

Visual Studio 2005/2008 Web Application Projects: Profile Class Auto Generation Workaround

I have been doing some coding with VS2008, and have been playing with the .NET Membership, Role, and Profile providers. I don’t use "Web Sites" when I create projects, instead I use "Web Applications" – what is the difference? Web Sites don’t really act like a first class application, there are some weird things with references, the bin directory, etc. Web Application act like a console app, or windows form app, the way you can reference assemblies, etc. There are a ton more differences I am sure, but those are the ones that stand out for me.

Now, with the Profile stuff in ASP.NET, you can use a Login control, and CreateUserWizard control, and then hook up your site to a SQL backend using the ASP.NET Membership provider. Everything works great. But you can also add custom properties (ex: First Name, Last Name, etc) to your user’s "Profile". You add these settings in the Web.Config

<profile enabled="true">
    <properties>
        <add name="FirstName" type="string"/>
        <add name="LastName" type="string"/>
        <group name="Address">
            <add name="Address1" type="string"/>
            <add name="Address2" type="string"/>
            <add name="City" type="string"/>
            <add name="State" type="Int32"/>
            <add name="Country" type="Int32"/>
            <add name="PostalCode" type="string"/>
        </group>
        <add name="PhoneNumber" type="string"/>
    </properties> 
</profile>

and then when you build your project, Visual Studio is supposed to auto create a class behind the scenes with those properties. This works fine if you use a "Web Site", but fails to do so when you have a "Web Application"

In VS2005, there was an add in you could install that would auto create this class on build, and there is one as well for VS2008 – Web Profile Builder.

You can use the Web Profile Builder which just creates a class for you, or you can create your own, or you can just code around it, like this:

CreateUserWizard cuwWiz = (CreateUserWizard)lgnView.FindControl("CreateUserWizard1");

ProfileBase p = ProfileBase.Create(cuwWiz.UserName, true);

p.SetPropertyValue("FirstName", ((TextBox)cuwWiz.CreateUserStep.ContentTemplateContainer.FindControl("txtFirstName")).Text);
p.SetPropertyValue("LastName", ((TextBox)cuwWiz.CreateUserStep.ContentTemplateContainer.FindControl("txtLastName")).Text);

p.GetProfileGroup("Address").SetPropertyValue("Address1", ((TextBox)cuwWiz.CreateUserStep.ContentTemplateContainer.FindControl("txtAddress1")).Text);
p.GetProfileGroup("Address").SetPropertyValue("Address2", ((TextBox)cuwWiz.CreateUserStep.ContentTemplateContainer.FindControl("txtAddress2")).Text);
p.GetProfileGroup("Address").SetPropertyValue("City", ((TextBox)cuwWiz.CreateUserStep.ContentTemplateContainer.FindControl("txtCity")).Text);
p.GetProfileGroup("Address").SetPropertyValue("State", Globals.IntParse(((DropDownList)cuwWiz.CreateUserStep.ContentTemplateContainer.FindControl("ddlState")).SelectedValue));
p.GetProfileGroup("Address").SetPropertyValue("PostalCode", ((TextBox)cuwWiz.CreateUserStep.ContentTemplateContainer.FindControl("txtPostalCode")).Text);
p.GetProfileGroup("Address").SetPropertyValue("Country", Globals.IntParse(((DropDownList)cuwWiz.CreateUserStep.ContentTemplateContainer.FindControl("ddlCountry")).SelectedValue));

p.SetPropertyValue("PhoneNumber", ((TextBox)cuwWiz.CreateUserStep.ContentTemplateContainer.FindControl("txtPhone")).Text);

p.Save();

Using ProfileBase lets you get around the use of the auto generated class, or the hand created class you might make. It does make it a little harder to set and get the properties though. If you did have the WebProfile or ProfileCommon class, you could just say

wp.FirstName = "Steve";

I wrestled with this profile stuff here for a good hour or two before I finally found on the net that Web Applications don’t auto create the class, etc. The class that it does generate though is derived from ProfileBase, so you can just use that and be OK. It would be nice if Web Application Projects did create the class though, it would have saved me a couple of head scratching hours. 🙂