catalyst2 community forums  

Go Back   catalyst2 community forums > Support > Database Support

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
Old 26-04-2005, 10:46 AM   #1 (permalink)
Registered User
 
naeems's Avatar
 
Join Date: Apr 2005
Posts: 4
OdbcConnection & M$ Access

Can anyone take a look at my C# code i'm using to connect to a M$ Access database and tell me what is wrong.

I'm getting the following error:
ERROR [07002] [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2.

and the code has been attached.

I keep getting an email back containing the above exception.
Attached Files
File Type: zip global.asax.zip (1.0 KB, 149 views)
naeems is offline   Reply With Quote
Old 26-04-2005, 11:31 AM   #2 (permalink)
Administrator
 
WhiskyFudge's Avatar
 
Join Date: Oct 2003
Posts: 1,484
Not quite sure whats generating that error but it could be possibly:
Code:
command.CommandType = CommandType.StoredProcedure;
needs to be:
Code:
command.CommandType = CommandType.Text;
Also does your email errors work? If my memory servers me correct localhost will not work for the SMTPServer, you need to use mail.yourdomain.com.

Hope that helps
__________________
Jason Robbins
jason@catalyst2.com
WhiskyFudge is offline   Reply With Quote
Old 26-04-2005, 11:59 AM   #3 (permalink)
Registered User
 
naeems's Avatar
 
Join Date: Apr 2005
Posts: 4
using localhost definately works! I'm receiving email with the error report.

I've just tried the CommandType.Text and still get the same results. Any more ideas?
naeems is offline   Reply With Quote
Old 26-04-2005, 12:08 PM   #4 (permalink)
Administrator
 
WhiskyFudge's Avatar
 
Join Date: Oct 2003
Posts: 1,484
Try replacing:
Code:
command.CommandText = "INSERT INTO Visitor(Referer, Browser) VALUES(@Referer, @Browser);";
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@Referer", (Request.UrlReferrer == null ? "none" : Request.UrlReferrer.ToString()));
command.Parameters.Add("@Browser", Request.UserAgent);
with:
Code:
command.CommandText = "INSERT INTO Visitor(Referer, Browser) VALUES(" + (Request.UrlReferrer == null ? "none" : Request.UrlReferrer.ToString()) + "," + Request.UserAgent + ");";
command.CommandType = CommandType.Text;
__________________
Jason Robbins
jason@catalyst2.com
WhiskyFudge is offline   Reply With Quote
Old 26-04-2005, 12:25 PM   #5 (permalink)
Registered User
 
naeems's Avatar
 
Join Date: Apr 2005
Posts: 4
OK, so I replaced the original code with the following:

Code:
OdbcConnection connection = new OdbcConnection(AppSettings.DbConn);
OdbcCommand command = connection.CreateCommand();
command.CommandText = "INSERT INTO Visitor(Referer, Browser) VALUES('";
command.CommandText += (Request.UrlReferrer == null ? "none" : Request.UrlReferrer.ToString());
command.CommandText += "', '" + Request.UserAgent + "');";
command.CommandType = CommandType.Text;
Now i'm getting "Operation must use an updateable query".
naeems is offline   Reply With Quote
Old 26-04-2005, 12:28 PM   #6 (permalink)
Registered User
 
naeems's Avatar
 
Join Date: Apr 2005
Posts: 4
Using OleDb instead of Odbc

If I use a OleDb connection object with an OleDbCommand, can I still use the database in the {root}/db?

If so, what will the path to the database be?
naeems is offline   Reply With Quote
Old 26-04-2005, 01:55 PM   #7 (permalink)
Administrator
 
Jacob's Avatar
 
Join Date: May 2003
Posts: 1,299
The probable reason you would be getting 'Operation must use an updateable query' is because the folder you have the database in does not have correct permissions. The /db has the correct permissions already and is much more secure than having the database in the wwwroot somewhere.

The absolute path to the /db is:

d:\domains\mydomain.com\db

Hope that helps, post back if you have any further queries.

Regards,

Jacob
Jacob is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 11:40 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.