Re: SQL OLEDB connection
From: Dan Guzman (danguzman@nospam-earthlink.net)
Date: 03/29/03
- Next message: Palani Perumal: "Does the ownerchip could be maintained across databases on different servers ?"
- Previous message: Maryam Rezvani: "Change password....."
- In reply to: Anna Sentyurin: "SQL OLEDB connection"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
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 >
- Next message: Palani Perumal: "Does the ownerchip could be maintained across databases on different servers ?"
- Previous message: Maryam Rezvani: "Change password....."
- In reply to: Anna Sentyurin: "SQL OLEDB connection"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|
|