VS 2013 preview - sqlConnection.Open() crashing - visual-studio-2013

This code works perfectly in VS 2010 and 2012.
Dim cmdText As String = "select * from master.dbo.sysdatabases where name=N'" & database & "'"
Dim bRet As Boolean = False
Using sqlConnection As SqlConnection = New SqlConnection(connString)
Try
sqlConnection.Open()
Using sqlCmd As SqlCommand = New SqlCommand(cmdText, sqlConnection)
Using reader As SqlDataReader = sqlCmd.ExecuteReader
bRet = reader.FieldCount > 1
reader.Close()
End Using
End Using
Catch ex As SqlException
MsgBox("Error Trying to Connect to database " & database & vbNewLine & ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
sqlConnection.Close()
End Try
End Using
But when I run it in 2013 this is the error I get at the sqlConnection.Open() command: -
An unhandled exception of type 'System.ExecutionEngineException'
occurred in System.Transactions.dll
If there is a handler for this exception, the program may be safely
continued.
I have found and tried http://connect.microsoft.com/VisualStudio/feedback/details/791339/fatalexecutionengineerror
But to no avail
Has anyone any pointers?
I am stuck.

Related

Issue with System.EnterpriseServices trying to connect to Oracle DB

I used VS2019 on Windows 10 64.
In a .NET Winform application (using .NET v5 framework), I'd like to interact with Oracle DB which is running on a distant server.
So, I installed SQL Developper, Oracle Client in C:\App\db_home. SQL Developper works fine and can access to the Oracle DB perfectly.
I add to my VS Project the reference which seems to be the good one (pretty hesistating on that part but "trying is the way to success") : C:\App\db_home\ODP.NET\bin\4\Oracle.DataAccess.dll
Everything seems ok:
Here's my code to get the connection working (the italic text was edited for posting this online)
Public Function OpenOracleBddConnexion()
Dim Public strOracleConnection As String = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=*Host_URL*)(PORT=*DB_Port*))) (CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=*SERVICE_NAME*))); User Id=*USER_ID*;Password=*User_ID*;"
Dim strMsgException As String = "Problème de connexion aux bases Oracles. " & strMsgErrorTellYourAdmin & vbCrLf & "-- Message d'erreur: "
Dim conn As New OracleConnection
Dim cmd As New OracleCommand
Dim adapter As New OracleDataAdapter
Try
conn.ConnectionString = strOracleConnection
conn.Open()
Exit Try
Catch ex As Exception
MsgBox(strMsgException & ex.Message, MsgBoxStyle.Critical, "Erreur Connexion Bases Oracle")
Return Nothing
Exit Try
End Try
End Function
Here is the cryptic error i had:
Could not load file or assembly 'System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Le fichier spécifié est introuvable.

Could not find installable ISAM while opening excel file with OLE driver

I am getting a "Could not find installable ISAM" error in the asp.net webform using visual basic. I am using .Net 4.6 framework. I tried different combinations of connection strings and I also tried with a single quote on Extended Properties as many online solutions suggested but the error did not go away. My code is as below:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim conn As OleDbConnection
Dim dta As OleDbDataAdapter
Dim dts As DataSet
Dim excel As String
excel = "C:\Users\ishfaq.babar\Downloads\aaa.xlsx"
'Dim openfiledialog As New OpenFileDialog
'conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excel + ";Extended Properties='Excel 12.0;'";")
conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\ishfaq.babar\Downloads\aaa.xlsx;Extended Properties='Excel 12.0;HDR=YES;Persist Security Info=False'")
dta = New OleDbDataAdapter("select * from [Sheet1$]", conn)
dts = New DataSet
dta.Fill(dts, "[Sheet1$]")
ExcelGridData.DataSource = dta
ExcelGridData.DataBind()
End Sub
i got error on line
dta.Fill(dts, "[Sheet1$]")
Moreover,I have installed both versions of ole drivers x64 and X86 and I had installed ole driver by command line as:
accessdatabaseengine /quiet
accessdatabaseengine_X64 /quiet
Because I was getting error from GUI Installer as:
microsoft.ace.oledb.12.0' provider is not registered on the local machine
ScreenShot of installed drivers is as follows:
OLE Drivers.Installed Access database Engine versions
ERROR has been resolved automatically with no change in code at all. Just after login again to my account after taking a break it runs successfully:
EDIT:
I Put conn.Open() after connection string.
New Code is As Below:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim conn As OleDbConnection
Try
Dim dta As OleDbDataAdapter
Dim dts As DataSet
Dim excel As String
excel = "C:\Users\ishfaq.babar\Downloads\aaa.xlsx"
'Dim openfiledialog As New OpenFileDialog
'conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excel + ";Extended Properties='Excel 12.0;'";")
conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\ishfaq.babar\Downloads\aaa.xlsx;Extended Properties='Excel 12.0;HDR=YES;Persist Security Info=False'")
conn.Open()
'PrintLine('ok')
' conn.Close()
dta = New OleDbDataAdapter("select * from [Sheet1$]", conn)
dts = New DataSet
dta.Fill(dts, "[Sheet1$]")
ExcelGridData.DataSource = dta
ExcelGridData.DataBind()
Catch ex As Exception
conn.Close()
End Try
End Sub
Read data successfully from excel file as below screenshot:
Result of data read from excel file

Reading Data from Serial Port RS232 in Visual Basic 2013 (Visual Studio .NET)

We are trying getting weight from weighing machine.
While reading in Hyper-terminal in windows XP using COM1 we getting
the right values. But reading data in Visual Basic 2013 (in Windows 10
Pro) on my laptop using USB to COM port convertor cable we are getting
different values like x, ?, 3, &, etc. Kindly suggest the solution so
that we can get the right data through code.
Our Code is:
With Me.mvSerialPort
.PortName = "COM11" ' as shown in device manager
.BaudRate = 2400
.Parity = Parity.None
.StopBits = StopBits.One
.DataBits = 8
.Handshake = Handshake.None
.DtrEnable = True
.RtsEnable = True
.NewLine = vbCrLf
.ReadTimeout = 1000
.WriteTimeout = 1000
End With
'Function Code
Private Function ReadCOM() As String
Do
If Me.mvThread_Stop = True Then Exit Do
Try
Try
If Me.mvSerialPort.IsOpen Then
Me.mvSerialPort.Close()
End If
Catch ex As Exception
'
End Try
Try
Me.mvSerialPort.Open()
If Me.mvSerialPort.IsOpen Then
'Thread.Sleep(200)
Thread.Sleep(Val(Me.TextBox4.Text))
Dim svMessage As String = ""
Try
'svMessage = Me.mvSerialPort.ReadLine()
svMessage = Me.mvSerialPort.ReadExisting
updateStatus(svMessage)
Catch ex As Exception
'Me.mvThread_Stop = True
End Try
End If
Me.mvSerialPort.Close()
Catch ex As Exception
Me.mvSerialPort.Close()
'
End Try
Catch ex As TimeoutException
'updateStatus(ex.ToString)
End Try
Loop
Return ""
End Function
Public Delegate Sub updateStatusDelegate(ByVal newStatus As String)
Public Sub updateStatus(ByVal newStatus As String)
Try
If Me.InvokeRequired Then
Dim upbd As New updateStatusDelegate(AddressOf updateStatus)
Me.Invoke(upbd, New Object() {newStatus})
Else
Dim svSplit() As String = Split(newStatus, " ")
Me.TextBox4.Text = svSplit(svSplit.Count - 1)
RichTextBox1.Text = newStatus & vbCrLf & RichTextBox1.Text
End If
Catch ex As Exception
'
End Try
End Sub

Visual Studio Login Program Issue

I am new to Visual Studio and I'm having a problem with my Login program.
Im attempting to allow a user 3 attempts to login to a system before the program aborts on the 4th attempt.
The problem I am having is even when I enter the correct username/password the program still view the credentials as a bad login attempt.
If I comment out the if/Elseif code I can login without issue..but obviously without the handling attempts which I need.
I am only a couple of days into Visual Studio so simple errors would be completely unknown to me at this stage..so any suggestions or obvious errors pointed out would be most appreciated.
Imports Oracle.DataAccess.Client
Public Class Form1
Public con As New OracleConnection
Public ds As New DataSet
Public Function Connect() As OracleConnection
Dim username As String = txtUsername.Text
Dim password As String = txtPassword.Text
Dim connectString As String = "Data Source=XE; user id=" & username & ";" & "Password=" & password & ";"
Dim con As New OracleConnection(connectString)
con.Open()
Return con
End Function
Public Function populateDS() As DataSet
ds = New DataSet
Dim sql As String
Dim da As OracleDataAdapter
sql = "SELECT * from Customer"
da = New OracleDataAdapter(sql, Connect())
da.Fill(ds, "DT_Customer")
con.Close()
Return ds
End Function
Dim Attempt As Integer = 1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
**If txtUsername.Text = "username" And txtPassword.Text = "Password"** Then
MsgBox("Welcome")
Customer.ShowDialog()
Me.Hide()
populateDS()
ElseIf Attempt = 3 Then
MsgBox("Maxium Attempts Reached")
Close()
Else
MsgBox("Username & Password Incorrect - Attempt " & Attempt & " of 3 ")
Attempt = Attempt + 1
txtUsername.Text = ""
txtPassword.Text = ""
txtUsername.Focus()
End If
End Sub
End Class

Multiple-step OLEDB Error for SQLSERVER.CE.OLEDB.3.5 Connection

I am trying to connect to a SQL Server Compact Edition .sdf file with following connection string;
connMRC.ConnectionString = "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source=" & App.Path & "\Freeweigh.sdf;"
I get the following error everytime I try running an SQL command or opening a recordset:
Multiple-step OLE DB generated errors. Check each OLE DB status value, if available. No work was done.
I am using VB 6.0 and SQL Server Compact 3.5 SP2
Here's the code:
Public Sub opnConnectionC()
'Code for opening the ADO Connection
chkConn = connMRC.State
If chkConn = adStateClosed Then
connMRC.ConnectionString = "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source=" & App.Path & "\Freeweigh.sdf;"
connMRC.Open
End If
End Sub
Public Sub opnRecordsetC(rsOpen As Recordset)
'Code for opening the ADO Recordset
chkRs = rsOpen.State
If chkRs = adStateClosed Then
rsOpen.Source = strSQLC
rsOpen.CursorType = adOpenDynamic
rsOpen.LockType = adLockOptimistic
rsOpen.ActiveConnection = connMRC
rsOpen.Open
End If
End Sub
Private Sub tmrUpload_Timer()
Dim cmdUpload As New ADODB.Command
Dim rsFetch As New ADODB.Recordset
Call opnConnectionC
strSQLC = "SELECT Product FROM VehicleWeights"
Call opnRecordsetC(rsFetch)
rsFetch.MoveFirst
MsgBox (rsFetch.Fields("Product").Value)
Call clsConnectionC
End Sub
You can only open a forward only, read only recordset

Resources