[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.odbcnet

MySQL, ODBC and "unhandled exception" system error

doctor doctor

3/31/2002 7:10:00 AM

The following code:

Dim cn As OdbcConnection, strConnString
strConnString =
"driver=MySQL;DATABASE=Photos;SERVER=localhost;UID=root;PWD=root;PORT=3306;O
PTION=512;"
cn = New OdbcConnection(strConnString)
Dim myString As String = "Select * from pictures"
Dim cmd As OdbcCommand = New OdbcCommand(myString)
Dim da As New OdbcDataAdapter("select * from pictures", "dsn=cn")
Dim ds As New DataSet()
da.Fill(ds, "pictures")
DataGrid1.DataSource = ds.Tables("pictures").DefaultView

generates this error at the da.Fill command:

An unhandled exception of type 'Microsoft.Data.Odbc.OdbcException' occurred
in microsoft.data.odbc.dll

Additional information: System error.

The equivalent code runs fine as an aspx file:

<script language="C#" runat="server">
protected void Page_Load(Object sender, EventArgs e)
{
string mySQLConnStr = "driver={MySQL};";
mySQLConnStr = mySQLConnStr + "server=localhost;";
mySQLConnStr = mySQLConnStr + "uid=root;";
mySQLConnStr = mySQLConnStr + "pwd=root;";
mySQLConnStr = mySQLConnStr + "database=Photos;";
mySQLConnStr = mySQLConnStr + "OPTION=17923";
OdbcConnection myConnection = new OdbcConnection
(mySQLConnStr);
string SQL = "select * from pictures";
OdbcDataAdapter myCommand = new OdbcDataAdapter(SQL,
myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "pictures");
MyDataGrid.DataSource=ds.Tables["pictures"].DefaultView;
MyDataGrid.DataBind();
}
</script>

????



3 Answers

Fredrick Bartlett

3/31/2002 5:09:00 PM

0

There is a hot fix for the ODBC32.dll. Variable length fields (VarChar,
Text) etc. with a null value will raise an error. The fix is not available
in the public domain. I spent about an hour with Developer Support trying to
get it. After several transfers a rep gave me the correct phone number(not
listed in support directory) If you EMail me I will give you the directions
necessary to get it.

"doctor doctor" <g_o_d99@hotmail.com> wrote in message
news:eBKG#IH2BHA.1324@tkmsftngp03...
> The following code:
>
> Dim cn As OdbcConnection, strConnString
> strConnString =
>
"driver=MySQL;DATABASE=Photos;SERVER=localhost;UID=root;PWD=root;PORT=3306;O
> PTION=512;"
> cn = New OdbcConnection(strConnString)
> Dim myString As String = "Select * from pictures"
> Dim cmd As OdbcCommand = New OdbcCommand(myString)
> Dim da As New OdbcDataAdapter("select * from pictures", "dsn=cn")
> Dim ds As New DataSet()
> da.Fill(ds, "pictures")
> DataGrid1.DataSource = ds.Tables("pictures").DefaultView
>
> generates this error at the da.Fill command:
>
> An unhandled exception of type 'Microsoft.Data.Odbc.OdbcException'
occurred
> in microsoft.data.odbc.dll
>
> Additional information: System error.
>
> The equivalent code runs fine as an aspx file:
>
> <script language="C#" runat="server">
> protected void Page_Load(Object sender, EventArgs e)
> {
> string mySQLConnStr = "driver={MySQL};";
> mySQLConnStr = mySQLConnStr + "server=localhost;";
> mySQLConnStr = mySQLConnStr + "uid=root;";
> mySQLConnStr = mySQLConnStr + "pwd=root;";
> mySQLConnStr = mySQLConnStr + "database=Photos;";
> mySQLConnStr = mySQLConnStr + "OPTION=17923";
> OdbcConnection myConnection = new OdbcConnection
> (mySQLConnStr);
> string SQL = "select * from pictures";
> OdbcDataAdapter myCommand = new OdbcDataAdapter(SQL,
> myConnection);
> DataSet ds = new DataSet();
> myCommand.Fill(ds, "pictures");
> MyDataGrid.DataSource=ds.Tables["pictures"].DefaultView;
> MyDataGrid.DataBind();
> }
> </script>
>
> ????
>
>
>


(David Sceppa)

4/1/2002 10:50:00 PM

0

doctor doctor

4/2/2002 6:40:00 AM

0

Thanks - problem solved

"David Sceppa" <davidsc@online.microsoft.com> wrote in message
news:7A1sv6b2BHA.2024@cpmsftngxa08...
>
> There are a couple problems in your Visual Basic .NET code.
> The constructor for the OdbcCommand was incorrect and you were
> using a different connection string in the OdbcDataAdapter's
> constructor. Try the following code instead:
>
> Dim strConn, strSQL As String
> strConn =
> "driver=MySQL;DATABASE=Photos;SERVER=localhost;UID=root;PWD=root;P
> ORT=3306;O
> PTION=512;"
> strSQL = "Select * from pictures"
> Dim da As New OdbcDataAdapter(strSQL, strConn)
> Dim ds As New DataSet()
> da.Fill(ds, "pictures")
> DataGrid1.DataSource = ds.Tables("pictures").DefaultView
>
> I hope this information proves helpful.
>
> David Sceppa
> Microsoft
> This posting is provided "AS IS" with no warranties,
> and confers no rights. You assume all risk for your use.
> © 2002 Microsoft Corporation. All rights reserved.