Click here to Skip to main content
Licence 
First Posted 17 Jul 2003
Views 115,957
Bookmarked 34 times

.NET MySQL Connexion V 1.2

Class Library for MySQL request
 
Part of The SQL Zone sponsored by
See Also

Introduction

This is a class library in VB.NET made for access on MySQL databases. You can use this library without creating functions for working on the databases.

For using this library, you must install :

and the

In this library, you have 3 classes:

  • ManipStringForMySQL: This class modifies the string for the SGBD
  • MySQL_Requettes: This class makes the request on the SGBD
  • MySQL_Utils : This class makes tests on the data of the SGBD

Visual Studio project screenshot

An example of the function with a dataset holding the results of the query:

Public Shared Function MyODBCDataset(ByVal ReqSQL As String, _
         ByVal LaBase As String, ByVal Server As String, _
         ByVal Password As String, ByVal User As String, _
         ByVal NomDataSet As String) As DataSet
    ' Connexion à un server MySQL 
    'avec le Driver ODBC 3.51 avec requette qui renvoie un dataset
    Dim MyConString As String = _
        "DRIVER={MySQL ODBC 3.51 Driver};SERVER=" & Server _
        & ";DATABASE=" & LaBase & ";UID=" & User _
        & ";PASSWORD=" & Password & ";OPTION=3;"

    Dim MyODBCConnexion As New OdbcConnection(MyConString)
    Try
        Dim ds As New DataSet()
        Dim cmd As OdbcDataAdapter = New 
        OdbcDataAdapter(ReqSQL, MyConString)
        Dim MyCommand As New OdbcCommand()
        Dim MyDataReader As OdbcDataReader
        cmd.Fill(ds, NomDataSet)
        MyODBCConnexion.Close()
        Return ds
    Catch MyOdbcException As OdbcException
    ' 
      HttpContext.Current.Response.Write(MyOdbcException.ToString)
    Catch MyException As Exception
    ' 
      HttpContext.Current.Response.Write(MyException.ToString)
    End Try
End Function

The call of this function may be like that:

Dim MonDatasetTemp As DataSet = MySQL_Requettes.MyODBCDataset(
               SQL,
               constantes.ODBCBase, 
               constantes.ODBCServer, 
               constantes.ODBCPwd, 
               constantes.ODBCUser, 
               "MonDataset")

Conclusion

This library is the first example I made for the MySQL use in my ASP.NET solutions. I hope it can be easy for use in your projects.

You can also see the French version of this article more directed for the creation and use of the class library :

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Romelard Fabrice (Alias F___)

Web Developer

Switzerland Switzerland

Member

I'm French Web developer and MVP.
My favorites languages are ASP.NET and SharePoint. I made a lot of projects in open source and many articles.
You can see all my articles on french developer sites like :
- http:/:www.asp-php.net
- http://www.aspfr.com
 
My technical blog is in French community :
- http://blogs.developpeur.org/fabrice69/
 
Romelard Fabrice [MVP]


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralThe trust relationship between this workstation and the primary domain failed. PinmemberMind Experts12:59 27 Jun '06  
Hi,
 
I have just started to develop with MYSQL.
I have a local installation of the MySql db, and am trying to connect to it using .Net 2.0
 

Here is my connection string.

 
Now when I go to a page which tries to connect to the db, it gives me this error: I do not get any opportunity to get in the code to any of my breakpoints.
 
==================================
Exception Details: System.SystemException: The trust relationship between this workstation and the primary domain failed.
Stack Trace:
 
[SystemException: The trust relationship between this workstation and the primary domain failed.
]
System.Security.Principal.NTAccount.TranslateToSids(IdentityReferenceCollection sourceAccounts, Boolean& someFailed) +1167
System.Security.Principal.NTAccount.Translate(IdentityReferenceCollection sourceAccounts, Type targetType, Boolean& someFailed) +42
System.Security.Principal.NTAccount.Translate(IdentityReferenceCollection sourceAccounts, Type targetType, Boolean forceSuccess) +46
System.Security.Principal.WindowsPrincipal.IsInRole(String role) +205
System.Web.Configuration.AuthorizationRule.IsTheUserInAnyRole(StringCollection roles, IPrincipal principal) +166
System.Web.Configuration.AuthorizationRule.IsUserAllowed(IPrincipal user, String verb) +393
System.Web.Configuration.AuthorizationRuleCollection.IsUserAllowed(IPrincipal user, String verb) +263
System.Web.Configuration.AuthorizationSection.IsUserAllowed(IPrincipal user, String verb) +45
System.Web.Security.UrlAuthorizationModule.OnEnter(Object source, EventArgs eventArgs) +286
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +167
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +117
=========================================
 
But if i start the application with a different connection string, like the one i used for SQL server: It errors out as while connecting, and I am able to debug et all.
Now I go back in and change the connection string to the actual one, i can go back to that page, and connect to the database just fine. But then it comes back to that “Trust” error randomly.
 
Any idea what is going on here?
 
All the elements are on my development machines. MySql server, IIS server, code all..
 
Any insight will be welcome.
 
-

 
Jainnys
http://www.mindexp.com
Mind Experts Inc.
Generalerror 403 !!! PinmemberLil`Buh1:23 16 Feb '04  
GeneralNot Support Authendication PinsussAnonymous22:12 18 Jan '04  
GeneralRe: Not Support Authendication PinmemberNazz21:59 25 Nov '08  
Generalnice work PinsussAnonymous4:28 16 Jan '04  
QuestionWhat? Pinmemberdog_spawn5:02 18 Jul '03  
AnswerRe: What? PinmemberJuergen Posny5:05 18 Jul '03  
Generaler ok Pinmemberdog_spawn5:15 18 Jul '03  
GeneralRe: er ok PinmemberRomelard Fabrice (Alias F___)5:44 18 Jul '03  
GeneralAh, pilote = driver Pinmemberdog_spawn5:59 18 Jul '03  
GeneralRe: Ah, pilote = driver PinsussNix_10:19 24 Aug '03  
GeneralAlready said Pinmemberdog_spawn10:41 24 Aug '03  
GeneralRe: Already said PinsussNix_9:43 30 Aug '03  
Answerhow ? Pinmemberdenise83840516:12 29 Aug '04  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120529.1 | Last Updated 18 Jul 2003
Article Copyright 2003 by Romelard Fabrice (Alias F___)
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid