473,383 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Problem with code behind update to MySQL

dbrewerton
115 100+
Ok everyone, when I do this update clause using code behind it gives me a stupid error that says:

Line: 6
Char: 62099
Error: Sys.WebForms.PageRequestManagerServerErrorExceptio n: Format of the initialization string does not conform to specification starting at index 0.
Code: 0
URL: http://localhost:1038/webapp/admin/assignuser.aspx

Now, my code for the SQL code behind is:

Expand|Select|Wrap|Line Numbers
  1.                 SqlConnection con = null;
  2.                 SqlCommand cmd = null;
  3.                 try
  4.                 {
  5.                     con = new SqlConnection();
  6.                     con.ConnectionString = "SqlDataSource4";
  7.                     cmd = new SqlCommand();
  8.                     cmd.Connection = con;
  9.                     cmd.Parameters.AddWithValue("?aspnet_id", Session["aspnet_id"]);
  10.                     cmd.Parameters.AddWithValue("?contact_id", Session["contact_id"]);
  11.                     cmd.Parameters.AddWithValue("?device_id", Session["device_id"]);
  12.                     con.Open();
  13.                     cmd.CommandText = "update egw_addressbook set aspnet_id = ?aspnet_id where contact_id = ?contact_id;";
  14.                     cmd.ExecuteNonQuery();
  15.                     cmd.CommandText = "update ewise_device set aspnet_id = ?aspnet_id where device_id = ?device_id;";
  16.                     cmd.ExecuteNonQuery();
  17.                 }
  18.                 catch (Exception)
  19.                 {
  20.                     throw;
  21.                 }
  22.                 finally
  23.                 {
  24.                     if (con.State.Equals(ConnectionState.Open)) con.Close();
  25.                 }
I am baffled, any idea what's wrong???
Nov 17 '09 #1

✓ answered by Curtis Rutland

Yeah, you have to use completely different objects. SqlConnection becomes OleDbConnection, SqlCommand becomes OleDbCommand, and the namespace is now System.Data.OleDb rather than System.Data.SqlClient.

Other than that it is pretty much the same.

15 2620
Curtis Rutland
3,256 Expert 2GB
I think the problem is your connection string. You are passing the literal string "SqlDataSource4" to the connection object.

A MySql conn string should look something like
Expand|Select|Wrap|Line Numbers
  1. "Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;"
Nov 18 '09 #2
dbrewerton
115 100+
When I use the code above, it gives me a logon failure even though I have dbowner. The logon I'm using works everywhere else so I'm really not sure what's wrong.
Nov 18 '09 #3
Curtis Rutland
3,256 Expert 2GB
Can you post your updated code for me? Thanks.
Nov 18 '09 #4
dbrewerton
115 100+
Expand|Select|Wrap|Line Numbers
  1. protected void Button1_Click(object sender, EventArgs e)
  2.     {
  3. //        DropDownList1.Enabled = true;
  4. //        DropDownList2.Enabled = true;
  5. //        DropDownList3.Enabled = true;
  6.  
  7.                 SqlConnection con = null;
  8.                 SqlCommand cmd = null;
  9.                 try
  10.                 {
  11.                     con = new SqlConnection();
  12.                     con.ConnectionString = "server=192.168.1.160;database=mytestdb;uid=username;pwd=nottelling;";
  13.                     cmd = new SqlCommand();
  14.                     cmd.Connection = con;
  15.                     cmd.Parameters.AddWithValue("aspnet_id", Session["aspnet_id"]);
  16.                     cmd.Parameters.AddWithValue("contact_id", Session["contact_id"]);
  17.                     cmd.Parameters.AddWithValue("device_id", Session["device_id"]);
  18.                     con.Open();
  19.                     cmd.CommandText = "update egw_addressbook set aspnet_id = ?aspnet_id where contact_id = ?contact_id;";
  20.                     cmd.ExecuteNonQuery();
  21.                     cmd.CommandText = "update ewise_device set aspnet_id = ?aspnet_id where device_id = ?device_id;";
  22.                     cmd.ExecuteNonQuery();
  23.                 }
  24.                 catch (Exception)
  25.                 {
  26.                     throw;
  27.                 }
  28.                 finally
  29.                 {
  30.                     if (con.State.Equals(ConnectionState.Open)) con.Close();
  31.                 }
  32.     }
Nov 18 '09 #5
Curtis Rutland
3,256 Expert 2GB
Is your DB on a nonstandard port?

Here's a good connection string resource:
http://www.connectionstrings.com/mysql
Use the one that fits your needs.

Let me know how it goes.
Nov 18 '09 #6
dbrewerton
115 100+
No, the standard MySQL port is 3306. I want to keep this as vanilla as possible.
Nov 18 '09 #7
Curtis Rutland
3,256 Expert 2GB
Hmm, odd. Post the exact exception text please.

EDIT: Oh, I think I know the problem.

The SqlClient and SqlCommand objects are native objects for MS SQL Server.

Use OleDb instead.

Here's the OleDb conn string:
Expand|Select|Wrap|Line Numbers
  1. "Provider=MySQLProv;Data Source=mydb;User Id=myUsername;Password=myPassword;"
The OleDb objects are very similar to the Sql objects, just named differently:
Take a look at this article. It has examples of using the OleDb objects.
Nov 18 '09 #8
dbrewerton
115 100+
Ok, here is the exact text:

Line: 6
Char: 62099
Error: Sys.WebForms.PageRequestManagerServerErrorExceptio n: Login failed for user 'username'.
Code: 0
URL: http://localhost:1038/webapp/admin/assignuser.aspx
Nov 18 '09 #9
Curtis Rutland
3,256 Expert 2GB
I edited my post, probably while you were posting. Check it out, try it out, and let me know how it works.
Nov 18 '09 #10
dbrewerton
115 100+
Well, I tried it but the system complains saying Keyword not supported: 'provider'. I'll look at that article too.
Nov 18 '09 #11
Curtis Rutland
3,256 Expert 2GB
Yeah, you have to use completely different objects. SqlConnection becomes OleDbConnection, SqlCommand becomes OleDbCommand, and the namespace is now System.Data.OleDb rather than System.Data.SqlClient.

Other than that it is pretty much the same.
Nov 18 '09 #12
dbrewerton
115 100+
Can you take a peek at this and tell me how to recode it? I have the aspnet_id in a query string named MyUserId and DropDownList1 value is the contact ID. I'd like to know how to put these variables into the code behind.
Expand|Select|Wrap|Line Numbers
  1.             con = new OleDbConnection();
  2.             con.ConnectionString = "server=192.168.1.160;database=mytestdb;uid=userna me;pwd=nottelling;";
  3.             cmd = new OleDbCommand();
  4.             cmd.Connection = con;
  5.             cmd.Parameters.AddWithValue("aspnet_id", Session["aspnet_id"]); <-- QueryStringValue
  6.             cmd.Parameters.AddWithValue("contact_id", Session["contact_id"]); <-- Value of dropdown list selection
  7.             con.Open();
  8.             cmd.CommandText = "update egw_addressbook set aspnet_id = ?aspnet_id where contact_id = ?contact_id;";
  9.             cmd.ExecuteNonQuery();
Nov 25 '09 #13
dbrewerton
115 100+
Ok, after recoding once again, I'm getting new error now. Page displays:
Server Error in '/evanhee_webapp' Application.
--------------------------------------------------------------------------------

ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.Odbc.OdbcException: ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

Code behind where problem coming from is:
Expand|Select|Wrap|Line Numbers
  1.     protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
  2.     {
  3.  
  4.         OdbcConnection con = null;
  5.         OdbcCommand cmd = null;
  6.  
  7.         try
  8.         {
  9.             con = new OdbcConnection();
  10.  
  11. //See the Following LINE:
  12.            con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;server=192.168.1.160;database=mydb;uid=username;pwd=nottelling;";
  13.             cmd = new OdbcCommand();
  14.             cmd.Connection = con;
  15.             cmd.Parameters.Add("?aspnet_id", OdbcType.Int).Value = (Session["MyUserId"] != null) ? Convert.ToInt32(Session["MyUserId"]) : 1;
  16.             cmd.Parameters.Add("?contact_id", OdbcType.Int).Value = (Session["contact_id"] != null) ? Convert.ToInt32(Session["contact_id"]) : 0;
  17.             cmd.Parameters.Add("?device_id", OdbcType.Int).Value = (Session["device_id"] != null) ? Convert.ToInt32(Session["device_id"]) : 0;
  18.             con.Open();
  19.             cmd.CommandText = "update egw_addressbook set aspnet_id = ?aspnet_id where contact_id = ?contact_id;";
  20.             cmd.ExecuteNonQuery();
  21.             cmd.CommandText = "update ewise_device set aspnet_id = ?aspnet_id where device_id = ?device_id;";
  22.             cmd.ExecuteNonQuery();
  23.         }
  24.         catch (Exception)
  25.         {
  26.             throw;
  27.         }
  28.         finally
  29.         {
  30.             con.Close();
  31.         }
  32.     }
Nov 30 '09 #14
Curtis Rutland
3,256 Expert 2GB
JET is MS Access's provider. Try changing your connection string to match the correct one for MySql:
Expand|Select|Wrap|Line Numbers
  1. Provider=MySQLProv;Data Source=mydb;User Id=myUsername;Password=myPassword;
Dec 1 '09 #15
dbrewerton
115 100+
Ok, thanks, I'll give that a shot
Dec 1 '09 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Mosher | last post by:
Hi all, I have an issue with php and/or mysql. I have a php form that writes "items" to a mysql database, including a description of the item. On the mysql server, "magic_quotes_gpc" is ON. I...
0
by: Peter Fleck | last post by:
I'm having some trouble updating a mysql database with a perl cgi. Here's the perl: $sql = "UPDATE grants SET agency2 = \"$agency2\" WHERE agency2 = \"$key\""; $rv = do($sql) or die "Can't...
0
by: hiisikukko | last post by:
I have created project management software with Java and MySql and i works fine. This applet gets and writes information directly to MySql database. Problem is that those sqlClauses below(update...
0
by: jwl | last post by:
I'm having a problem with a bit of code that I have "adopted". It was partially complete when I took it over. The function of the code is to read a log file, locate files described in that log...
4
by: Kenneth P | last post by:
Hi All, I've installed MySql Connector.Net and it works very well if you not do code behind. But if you do code behind then in the declaration with namespaces you'll get an error, a line...
6
by: Mikey G | last post by:
Hi, Here is a shorter code example since the last message I posted got truncated. So the problem is I created a simple VB.NET 2003 application through Visual Studio that connects to a MySQL...
9
by: zMisc | last post by:
When I try to update record, I kept getting this error: Row cannot be located for updating. Some values may have been changed since it was last read. No other users are accessing the database...
3
by: Juan Antonio Villa | last post by:
Hello, I'm having a problem replicating a simple database using the binary log replication, here is the problem: When the master sends an update to the slave, an example update reads as follows:...
2
osward
by: osward | last post by:
Hello there, I am using phpnuke 8.0 to build my website, knowing little on php programing. I am assembling a module for my member which is basically cut and paste existing code section of...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.