Re: SQL OLEDB connection

From: Dan Guzman (danguzman@nospam-earthlink.net)
Date: 03/29/03


From: "Dan Guzman" <danguzman@nospam-earthlink.net>
Date: Fri, 28 Mar 2003 22:40:47 -0600


You can get error details from the OleDbException object. Rather than
use the legacy VB syntax, you can employ a Try-Catch block in VB.Net.
For example:

    Try

        'your OleDb code here

    Catch oleDbException As OleDb.OleDbException

        Dim messages As New StringWriter()
        messages.WriteLine("Database error:")
        Dim oleDbError As OleDb.OleDbError
        For Each oleDbError In oleDbException.Errors
            messages.WriteLine(oleDbError.Message)
        Next oleDbError
        Throw New ApplicationException(messages.ToString())

    End Try

-- 
Hope this helps.
Dan Guzman
SQL Server MVP
-----------------------
SQL FAQ links (courtesy  Neil Pike):
http://www.ntfaq.com/Articles/Index.cfm?DepartmentID=800
http://www.sqlserverfaq.com
http://www.mssqlserver.com/faq
-----------------------
"Anna Sentyurin" <a-ansent@microsoft.com> wrote in message
news:02d501c2f58e$9bea2610$a101280a@phx.gbl...
> I'm having exception on connection with database, I wonder
> what's wrong here
> Option Explicit On
> Imports System
> Imports System.IO
> Imports System.Data.SqlDbType
> Imports System.Data.SqlTypes
> Imports System.Data.SqlClient
> Imports System.Data.OleDb.OleDbConnection
>
> Public Class Add
>     Shared Sub main()
>         Dim Add = New DB_Check()
>         Add.DB_ADODB()
>     End Sub
>     Public Sub DB_Check()
>         On Error GoTo ErrorHandler
>         Dim strConnectionString As String
>         Dim Conn As System.Data.OleDb.OleDbConnection
>         ' Provider=MSDAORA; Data Source=ORACLE8i7; User
> ID=OLEDB; Password=OLEDB
>         ' Provider=Microsoft.Jet.OLEDB.4.0; Data
> Source=c:\bin\LocalAccess40.mdb;
>         'Provider=SQLOLEDB;Data
> Source=MySQLServer;Integrated Security=SSPI;
>
>         'GSAPERFSQL01
>         strConnectionString = "User
> ID=softlib_user;Password=burlapcoats;Initial
> Catalog=SMS_GDDG_TEST;Provider=SQLOLEDB;Data
> Source=GSAPERFSQL01;Connect Timeout=30"
>         Conn = New System.Data.OleDb.OleDbConnection
> (strConnectionString)
>
>
>         Dim selectCMD As System.Data.OleDb.OleDbCommand =
> New System.Data.OleDb.OleDbCommand("select * from
> dbo.tblSMSSurveySession", Conn)
>
>
>         Dim custDA As System.Data.OleDb.OleDbDataAdapter =
> New System.Data.OleDb.OleDbDataAdapter()
>         custDA.SelectCommand = selectCMD
>
>         Dim custDS As DataSet = New DataSet()
>
>         custDA.Fill(custDS, "dbo.tblSMSSurveySession")
>
>         Dim pRow
>         For Each pRow In custDS.Tables
> ("dbo.tblSMSSurveySession").Rows
>             Console.WriteLine(pRow("CustomerID").ToString
> ())
>
>         Next
>
>         Exit Sub
> ErrorHandler:
>         Err.Raise(Err.HelpFile & " ", " " &
> Err.Number, " " & Err.Description)
>
>     End Sub
>
>    End Class
>


Relevant Pages

  • Re: Interaction between the classes
    ... Imports System.Windows.Forms ... Public Class myKeyClass Implements owf.IMessageFilter ... Overridable Function PreFilterMessageAs Boolean Implements owf.IMessageFilter.PreFilterMessage ... Public Sub New ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Intercepting the WM_HELP message
    ... Imports System.Drawing ... End Sub ... Public Class MessageFilter ... eMVP" wrote in message ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Data access and vb class file from .net novise
    ... after Imports myapp.net.Class1 ... > Public Class WebForm3 ... > Private Sub Page_Load(ByVal sender As System.Object, ... > Shared Function getSimpleData ...
    (microsoft.public.dotnet.framework.adonet)
  • vb.net error while registering evevents
    ... Evidence assemblySecurity, String[] args) ... Imports System.Runtime.Remoting.Channels.Http ... Public Class Client ... Public Sub New ...
    (microsoft.public.dotnet.languages.vb)
  • RE: Problems implementing the IMessageFilter to filter keypress events
    ... Imports System.Reflection ... Private Sub frmMain_Load(ByVal sender As Object, ...
    (microsoft.public.windowsce.app.development)