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: - SqlConnection con = null;
-
SqlCommand cmd = null;
-
try
-
{
-
con = new SqlConnection();
-
con.ConnectionString = "SqlDataSource4";
-
cmd = new SqlCommand();
-
cmd.Connection = con;
-
cmd.Parameters.AddWithValue("?aspnet_id", Session["aspnet_id"]);
-
cmd.Parameters.AddWithValue("?contact_id", Session["contact_id"]);
-
cmd.Parameters.AddWithValue("?device_id", Session["device_id"]);
-
con.Open();
-
cmd.CommandText = "update egw_addressbook set aspnet_id = ?aspnet_id where contact_id = ?contact_id;";
-
cmd.ExecuteNonQuery();
-
cmd.CommandText = "update ewise_device set aspnet_id = ?aspnet_id where device_id = ?device_id;";
-
cmd.ExecuteNonQuery();
-
}
-
catch (Exception)
-
{
-
throw;
-
}
-
finally
-
{
-
if (con.State.Equals(ConnectionState.Open)) con.Close();
-
}
I am baffled, any idea what's wrong???
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
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 - "Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;"
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.
Can you post your updated code for me? Thanks.
- protected void Button1_Click(object sender, EventArgs e)
-
{
-
// DropDownList1.Enabled = true;
-
// DropDownList2.Enabled = true;
-
// DropDownList3.Enabled = true;
-
-
SqlConnection con = null;
-
SqlCommand cmd = null;
-
try
-
{
-
con = new SqlConnection();
-
con.ConnectionString = "server=192.168.1.160;database=mytestdb;uid=username;pwd=nottelling;";
-
cmd = new SqlCommand();
-
cmd.Connection = con;
-
cmd.Parameters.AddWithValue("aspnet_id", Session["aspnet_id"]);
-
cmd.Parameters.AddWithValue("contact_id", Session["contact_id"]);
-
cmd.Parameters.AddWithValue("device_id", Session["device_id"]);
-
con.Open();
-
cmd.CommandText = "update egw_addressbook set aspnet_id = ?aspnet_id where contact_id = ?contact_id;";
-
cmd.ExecuteNonQuery();
-
cmd.CommandText = "update ewise_device set aspnet_id = ?aspnet_id where device_id = ?device_id;";
-
cmd.ExecuteNonQuery();
-
}
-
catch (Exception)
-
{
-
throw;
-
}
-
finally
-
{
-
if (con.State.Equals(ConnectionState.Open)) con.Close();
-
}
-
}
No, the standard MySQL port is 3306. I want to keep this as vanilla as possible.
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: - "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.
I edited my post, probably while you were posting. Check it out, try it out, and let me know how it works.
Well, I tried it but the system complains saying Keyword not supported: 'provider'. I'll look at that article too.
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.
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. -
con = new OleDbConnection();
-
con.ConnectionString = "server=192.168.1.160;database=mytestdb;uid=userna me;pwd=nottelling;";
-
cmd = new OleDbCommand();
-
cmd.Connection = con;
-
cmd.Parameters.AddWithValue("aspnet_id", Session["aspnet_id"]); <-- QueryStringValue
-
cmd.Parameters.AddWithValue("contact_id", Session["contact_id"]); <-- Value of dropdown list selection
-
con.Open();
-
cmd.CommandText = "update egw_addressbook set aspnet_id = ?aspnet_id where contact_id = ?contact_id;";
-
cmd.ExecuteNonQuery();
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: -
protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
-
{
-
-
OdbcConnection con = null;
-
OdbcCommand cmd = null;
-
-
try
-
{
-
con = new OdbcConnection();
-
-
//See the Following LINE:
-
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;server=192.168.1.160;database=mydb;uid=username;pwd=nottelling;";
-
cmd = new OdbcCommand();
-
cmd.Connection = con;
-
cmd.Parameters.Add("?aspnet_id", OdbcType.Int).Value = (Session["MyUserId"] != null) ? Convert.ToInt32(Session["MyUserId"]) : 1;
-
cmd.Parameters.Add("?contact_id", OdbcType.Int).Value = (Session["contact_id"] != null) ? Convert.ToInt32(Session["contact_id"]) : 0;
-
cmd.Parameters.Add("?device_id", OdbcType.Int).Value = (Session["device_id"] != null) ? Convert.ToInt32(Session["device_id"]) : 0;
-
con.Open();
-
cmd.CommandText = "update egw_addressbook set aspnet_id = ?aspnet_id where contact_id = ?contact_id;";
-
cmd.ExecuteNonQuery();
-
cmd.CommandText = "update ewise_device set aspnet_id = ?aspnet_id where device_id = ?device_id;";
-
cmd.ExecuteNonQuery();
-
}
-
catch (Exception)
-
{
-
throw;
-
}
-
finally
-
{
-
con.Close();
-
}
-
}
JET is MS Access's provider. Try changing your connection string to match the correct one for MySql: - Provider=MySQLProv;Data Source=mydb;User Id=myUsername;Password=myPassword;
Ok, thanks, I'll give that a shot
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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:...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
| |