D
DraguVaso
Hi,
In a VB.NET-application I use this to open a Database Connection:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim strConn As String
strConn = "Server=BESQL1;DataBase=VocalcomCetelem;User
ID=vocalcomcetelem;Password=vocalcomcetelem;Trusted_Connection=False"
Dim strSql As String
strSql = "SELECT TOP 1 * " & _
"FROM tblCalls " & _
"ORDER BY CallID DESC"
Dim dtrSql As SqlDataReader
Dim conSql As SqlConnection
conSql = New SqlConnection(strConn)
Dim cmdSql As SqlCommand
Try
conSql.Open()
cmdSql = New SqlCommand(strSql, conSql)
dtrSql = cmdSql.ExecuteReader(CommandBehavior.SingleRow)
dtrSql.Read()
If dtrSql.HasRows Then
MessageBox.Show(dtrSql.Item("tdcaNCartphy").ToString)
End If
Catch ex As Exception
MessageBox.Show(ex.Message & ex.StackTrace)
End Try
End Sub
Sometimes it gives me an error when opening the Connection (on the
conSql.Open() ).:
Like this with MDAC 2.7 installed:
The .Net Data SQL Provider (System.Data.SqlClient) requires Microsoft Data
Access Components(MDAC) version 2.6 or later.
at System.Data.SqlClient.ConnectionPool.GetConnection(Boolean&
isInTransaction)
at
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnec
tionString options, Boolean& isInTransaction)
at System.Data.SqlClient.SqlConnection.Open()
Or this with MDAC 2.8:
Object reference not set to an instance of an object.
at System.Data.SqlClient.ConnectionPool.GetConnection(Boolean&
isInTransaction)
at
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnec
tionString options, Boolean& isInTransaction)
at System.Data.SqlClient.SqlConnection.Open()
So it seems I get troubles to get a (pooled) connection. Is there a 'safer'
way to get a connection? Using OleDB or Odbc? Or what can I do to get rid of
the error and get always my connection?
Thanks a lot in advance,
Pieter
In a VB.NET-application I use this to open a Database Connection:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim strConn As String
strConn = "Server=BESQL1;DataBase=VocalcomCetelem;User
ID=vocalcomcetelem;Password=vocalcomcetelem;Trusted_Connection=False"
Dim strSql As String
strSql = "SELECT TOP 1 * " & _
"FROM tblCalls " & _
"ORDER BY CallID DESC"
Dim dtrSql As SqlDataReader
Dim conSql As SqlConnection
conSql = New SqlConnection(strConn)
Dim cmdSql As SqlCommand
Try
conSql.Open()
cmdSql = New SqlCommand(strSql, conSql)
dtrSql = cmdSql.ExecuteReader(CommandBehavior.SingleRow)
dtrSql.Read()
If dtrSql.HasRows Then
MessageBox.Show(dtrSql.Item("tdcaNCartphy").ToString)
End If
Catch ex As Exception
MessageBox.Show(ex.Message & ex.StackTrace)
End Try
End Sub
Sometimes it gives me an error when opening the Connection (on the
conSql.Open() ).:
Like this with MDAC 2.7 installed:
The .Net Data SQL Provider (System.Data.SqlClient) requires Microsoft Data
Access Components(MDAC) version 2.6 or later.
at System.Data.SqlClient.ConnectionPool.GetConnection(Boolean&
isInTransaction)
at
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnec
tionString options, Boolean& isInTransaction)
at System.Data.SqlClient.SqlConnection.Open()
Or this with MDAC 2.8:
Object reference not set to an instance of an object.
at System.Data.SqlClient.ConnectionPool.GetConnection(Boolean&
isInTransaction)
at
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnec
tionString options, Boolean& isInTransaction)
at System.Data.SqlClient.SqlConnection.Open()
So it seems I get troubles to get a (pooled) connection. Is there a 'safer'
way to get a connection? Using OleDB or Odbc? Or what can I do to get rid of
the error and get always my connection?
Thanks a lot in advance,
Pieter