Archive for the ‘.net’ Category

ODBC & .NET TableAdapters

Wednesday, August 29th, 2007

When using an ODBC connection the table adapters will not allow you to add variables. you cannot use the @var syntax as with SQL Server. The only syntax available is the same when using variables to a MS Access DB. You must use ‘?’ where a variable will go eg.

SELECT * FROM ? where dog = ‘?’

The variables are used in the order that you add them to the query. This makes TableAdapters quite restricted and to me, useless… if they already weren’t too clunky.

You should use a good old sql query in the page, or create your own DAL as a class.

A simple ODBC query can be made using a simple function similar to:

using System.Data.Odbc;
 
public OdbcDataReader query(string queryString)
{
    OdbcCommand command = new OdbcCommand(queryString, connection);
    OdbcDataReader result = command.ExecuteReader();
    return result;
}

The Returned result can then be bound to a Repeater, DataGrid, etc

Using MySql with Visual Web Developer Express

Wednesday, August 29th, 2007

As a reforming PHP MySql developer, one thing i really love in LAMP development is the simplicity and no fuss approach. Mysql is small (22mb download) fast and quite capable of most website datastorage. Also the fact that it doesnt cost $5000.00 per processor… thats good too.

So it seems like a good choice to use the advantages of the .NET framework, with the power of MySql. Is this available for VWD Express users however?The answer is yes!

Due to restrictions on the pluginability (technically speaking) VWD Express cannot install the Native Mysql for .NET connectors (mysql conector .net) which would give the best performanc. If you use Visual Studio 2005 then this would be the best choice.

To use Mysql with Visual Web Developer 2005 install Mysql ODBC as follows:

1. Download the ODBC data drivers .

2. Setup your ODBC connection

3. in your config.xml or connection .NET SqlDataSource Object use the mysql connection string found here

In your config.xml you will set up a connection similar to this:

<connectionstrings>
<add name="ConnectionString"
	connectionString="Driver={MySQL ODBC 3.51 Driver};
	Server=localhost;
	Database=test;
	User=root;
	Password=;
	Option=3;"
     providerName="System.Data.Odbc">
     </add>
</connectionstrings>

using IIS5.1 with multiple sites

Wednesday, August 29th, 2007

Okay, as a starting point for learning .NET i installed Visual Web Developer Express. Even though it gives you the option to test a website with the ‘view in browser’ option (which launches a temporary server at some crazy port eg. locahost:1076), I thought it was essential to be developing on a real IIS server. Not setting up my server properly cause me many hours of greif and confusion.

The catch with using IIS5.1 for developing .NET websites is that it only allows you to setup ONE website (domain.. whatever). As i have setup and developed PHP on Apache Development servers before i thought this would be fine to work in a similar way, and proceeded to setup my different sites (as i did some tests) in a separate folders. Then by using folder browsing i could access the different sites. WRONG!

eg:
d:/website/ ( allow folder browsing to select a site)
d:/website/site1/
d:/website/site2/

and access them as:
http://localhost/
http://localhost/site1/default.aspx
http://localhost/site2/default.aspx

This works fine for Php sites running on Apache as all of you code is custom (or you set a base path). Its wreaks havok with .NET however. Forms authentication in the config.xml errors. the ~/ file addressing errors, which caused me not to use it at first. Every piece of example code that i downloaded had strings of errors. Solution: Virtual Folders

In Explorer you can click on the folder and under properties>web sharing and select ’share this folder’ then give it an alias. The alias is used like this:

http://localhost/alias/

If you have access this alias and a login box appears you need to change the websites permissions (change it form forms authentication to allow your windows user). This can be changed by going to control panel > administrative tools > IIS , then under the default website there should be the alias you’ve created. goto its properties > directory security , and press ‘edit’ on anonymous access and allow anonymous access. This may be insecure, but hey… you dont know anything about servers do you… so i trust you dont care :P