connection to Pervasive database slow - vb.net

This has been an on going issue at my place of work. Previously, we had a co-op programming student write us some applications using C# which ran well on his laptop, but once the applications were put to use on different computers, the connection to the pervasive database because painfully slow.
Now I am writing a simple VB.net application which need to query the Pervasive database, and I'm running into the same issue.
here's my code:
'PSQL variables
Dim myPsqlConnection As PsqlConnection = New PsqlConnection("ServerName=FILESERVER;ServerDSN=SAGE2")
Dim queryString As String
queryString = "SELECT NAME FROM CUSTOMER"
Dim MyCommand As New PsqlCommand(queryString, myPsqlConnection)
Dim MyReader As PsqlDataReader
Dim tempCustname As String
Try 'open conncetion to Pervasive DB
myPsqlConnection.Open()
Catch ex As Exception
MsgBox("COULD NOT OPEN A CONNECTION TO THE DATABASE" & vbCrLf & ex.Message)
Exit Sub
End Try
Try 'execute Pervasive query
MyReader = MyCommand.ExecuteReader
Catch ex As Exception
MsgBox("QUERY ERROR" & vbCrLf & ex.Message)
Exit Sub
End Try
If MyReader.HasRows = False Then
MsgBox("NO RESULTS FOUND")
Exit Sub
End If
While (MyReader.Read)
tempCustname = MyReader("NAME").ToString()
Customers.Items.Add(tempCustname)
End While
MyReader.Close()
myPsqlConnection.Close()
I stepped through the program and it take about 30 seconds to get past the line where it opens the connection.
As for the specs (I'll do my best):
My computer is quite powerful (16 gb or ram, 6 core AMD processor at 3.0 Ghz per core, windows 7 home 64 bit)
Pervasive.Data.SqlClient Version 3.2
Compiling with Microsoft Visual Basic 2010 Express
There are very few computers on this network (about 7), and I have no such trouble with MS Access databases. Our server is new 2 years ago, and out network has been upgraded to a GB connection. I should note I know very little about databases in general, let alone connecting with VB. I'm not really the best person to be doing this, but I'm still the most qualified person in our small company.

I've got it working now. The solution was to first install the database in the pervasive control center. First by selecting "new database" from the main window of the PCC and filling in the database name, location, username and password.
Next I changed the connection from pervasive ADO to OLEDB. My connection string now looks like this:
Dim myPsqlConnection As OleDbConnection = New OleDbConnection("Provider=PervasiveOLEDB;Data Source=DatabaseName;Location=FILESERVER")
Thanks to all everyone for your help!

Related

dBaseIV file creation from SQL Server 2016 database

I have a requirement as follows: on click of a link button on a web page, I have to fetch some records from a SQL Server 2016 database and convert them into dBaseIV format (.env, .ad1, .ad2, .veh) files and show a download/save as popup on the page where the end user would be able to download the files individually.
Any leads would be appreciated.
dBaseIV files expected on click of link button
This is like 90's requirement - a lot from memory ...
This is a VS 2017 console app ..., creates a DBaseIV file called bill and inserts a record, of course the logic to create, read etc is not included - also
System.IO.File.Exists is of dubious reliability on 64bit systems - someone else might have a better solution
I don't use IIS - so no idea on how to setup downloads there
and - I ran this on a Dell Windows 10 machine, the dBaseIV driver existed in ODBC
Module Module1
Sub Main()
Dim connectionString As String = "Driver={Microsoft dBase Driver (*.dbf)};DBQ=C:\temp\"
Using cn As New Odbc.OdbcConnection(connectionString)
cn.Open()
If Not System.IO.File.Exists("C:\Temp\books.dbf") Then
Using cmd As New Odbc.OdbcCommand("CREATE TABLE BOOKS (title char(50))", cn)
cmd.ExecuteNonQuery()
End Using
End If
Using cmd As New Odbc.OdbcCommand("INSERT INTO BOOKS (title) VALUES('The Story of Bill')", cn)
cmd.ExecuteNonQuery()
End Using
cn.Close()
End Using
Console.Write("done")
Console.ReadKey()
End Sub
End Module

Login failed for user 'user' VB.NET app and SQL connection

please see SQL Management Screen Shot Here
I am getting:
system.data.sqlclient.sqlexception: ' login failed for user 'public_user'.'
when I run my application on VB.NET. Please see the link to check settings on my SQL management studio. This application was running flawlessly previously, however I swapped my HDD to SSD and reinstalled SQL and Visual Studio. Since then I am failing to login as public_user.
I ran a query on SQL as public_user and I am not getting any error message. When I run the application, it does connect to SQL on the app, but it fails to load table1 on datagridview.
I've put tableadapter at the beginning on the mainform, at the end, under sqlconnection1.open, basically any possible places, however I am still getting the same error.
The source code is below, please help me to find the solution:
VB.NET
Microsoft SQL Server 2008 R2
Windows 10 OS
Timer1.Enabled = True
Dim sqlconnection1 As New SqlConnection("server = xxx-xxx-xxx;user id=public_user; password=xxxxxx; Trusted_Connection=True; connection timeout=5")
Dim cmdsql As New SqlCommand
cmdsql.CommandText = "SELECT * FROM [LM2].[dbo].[Table_1]"
cmdsql.CommandType = CommandType.Text
cmdsql.Connection = sqlconnection1
Me.Table_1TableAdapter.Fill(Me.LM2DataSet2.Table_1)
Try
sqlconnection1.Open()
If ConnectionState.Open Then
MsgBox("Connected To SQL")
Else
MsgBox("Failed To Connect SQL")
End If
Catch ex As DataException
MessageBox.Show(ex.Message)
End Try
i've found the solution. When i copied SLN from the old HDD and transferred to SSD, for some reason it automatically deleted the ID and password on ConnectionString settings. I've entered those details on main settings and it is working fine. I had in total 5 SQL Databases which was connecting to my App, and all of them were using same login details for public_user. when i enter credentials it worked for all SQL databases.

How do I create an Azure SQL Database copy during runtime?

I am new to VB.NET and Azure SQL services and I have spent the last 3 days searching for an answer and cannot come up with an answer I can truly understand. Here is my scenario and problem:
I have a VB.NET application where a user will log into their account and have their own set of tables under their own Azure SQL Database. I would like my program to automatically create their database for them (using their own selected name), which would be a database copy of an existing empty Database in Azure.
I can already access the data tables in my master database, but I do not know how to make a copy of it from my program during runtime. When I run my application and it debugs the following snippit of code, I get an exception error saying "You must be logged into the master database" I'm not sure how to resolve that error from popping up as I am using the master admin account in my normal SQL connection string.
Private Sub BtnActivate_Click(sender As Object, e As RoutedEventArgs)
If passwrd1.Password <> passwrd2.Password Then
MsgBox("Password doesn't match Confirm Password.", vbOKOnly)
Else
Dim commandString = "CREATE DATABASE " & dbname.Text & " AS COPY OF DBDEV;"
Using connection As New SqlConnection(My.Settings.DBDEVConnectionString)
Dim command As New SqlCommand(commandString, connection)
Try
connection.Open()
command.ExecuteNonQuery()
MsgBox("DATABASE SETUP. USE " & dbname.Text & "AS DBNAME TO CONNECT TO")
Catch ex As Exception
Throw ex
End Try
End Using
End If
End Sub
Please help, I've been moving nowhere and everything I'm searching for doesn't give me a clear answer to this simple scenario.
After many attempts, I solved the problem: in my connection string, I had the initial catalog default to my database and so I changed it to say "master" (even though I don't have a database named master) and it performed the Database copy for me. Woohoo!

Errors With SQLite and VB.net when reading database

I seem to be receiving random error messages when trying to read queries from a SQLite DB stored on a network drive. On my development machine, I rarely ever get an error, but users are reporting random errors such as:
Unable to open database. File is encrypted or is not a database
Database disk image is malformed
Or it just doesn't return any data.
My code looks like such:
Private Sub LoadStoreCalls()
Dim tmpID As String
Dim QryString As String
Dim SQLconnect As New SQLite.SQLiteConnection()
SQLconnect.ConnectionString = "Data Source=" & SpiceWorksPath & ";New=False;Compress=True;Read Only=True;"
Try
'Open a connection to the database
SQLconnect.Open()
'Get StoreCode
tmpID = Mid(StoreCode, 2) & "-" & StoreName
QryString = "SELECT id, summary, status, c_location, c_store_device FROM tickets WHERE status = 'open' AND c_location = '" & tmpID & "'"
Dim ExQry As New SQLiteCommand(QryString, SQLconnect)
ExQry.CommandType = CommandType.Text
Dim da As New SQLiteDataAdapter(ExQry)
dasSpice.Clear()
da.Fill(dasSpice, "Calls")
SQLconnect.Close()
Catch ex As Exception
If SQLconnect.State = ConnectionState.Open Then SQLconnect.Close()
MsgBox(ex.Message)
End Try
End Sub
The problem is that my application relies on this data being returned to populate additional entries of a datagridview control, and because I cannot replicate this error on my development machine using debug, I cannot find where the fault is occurring.
If the user gets one of these errors, they usually keep trying to run the query and eventually it will work. Or they just exit my application and go back in and then it seems to work for a while. The errors are random and not always from running the same query.
I'm assuming it's due to an issue talking to an SQLite DB on a shared drive, but I can't find any information regarding setting timeouts. I also can't work out how to 'catch' the error because I can't replicate it myself. I have tried adding logging details to the Catch event handler, but it simply just returns me the error message (above) in the logs.
Any help would be greatly appreciated.
Thanks
After many hours of troubleshooting and researching I found that SQLite does not play well with remote connections. Not only was it causing errors in my application, it was also throwing errors in the parent application.
My alternative was to write an application to query the database that ran locally on the SQLite machine. This fixed all of my issues.
For anyone interested...

How do I resolve "ODBC-connection fail"

My Program is "Searching Employee" Use VB web application in Visual Studio 2008
and I use Database in Microsoft Access
I program it in my computer it work 100%. But When I move the project to other computer for upload to server, it have error
ODBC--connection to 'SQL ServerWDT02418\SQLEXPRESS' failed.
WDT02418 is my Computer's name. But I run the project in other computer.
I use the Database connection like this
Function CountEmpData(ByVal EN As String, ByVal Area As String, ByVal Product_type As String) As Integer
Dim CounterEmpData As Integer
Try
Dim ole As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\PROJECT_WD\e-OJT_Project6\Database\Employee.mdb")
ole.Open()
Dim sqlCommand As String = "SELECT COUNT(*) AS 'Counter' FROM Employee WHERE (Emp_ID LIKE '%" + EN + "%') AND (Area LIKE '%" + Area + "%') AND (Product_Type LIKE '%" + Product_type + "%')"
Dim myCommand As New OleDbCommand(sqlCommand, ole)
Dim myReader As OleDbDataReader = myCommand.ExecuteReader()
While myReader.Read()
CounterEmpData = myReader.GetInt32(0)
End While
myReader.Close()
ole.Close()
Catch ex As Exception
End Try
Return CounterEmpData
End Function
It alert error at line
Dim myReader As OleDbDataReader = myCommand.ExecuteReader()
Someone please help me!!
There's nothing computer-specific in the code above, apart from the location of the Access file, but the absence of that wouldn't produce the error above. So I think the problem must lie in your .mdb database, and I suspect the issue is that it contains tables that are linked to a SQL Server which only code running on your machine can get to.
I would troubleshoot this by using the Microsoft Access UI to open the access database on one of the other computers, opening the Employee table and seeing if you still get an error. If you do, you'll know that it's the Access database that's at fault rather than your code. I would guess at this point that remote connections are not set up on SQL Server Express (see here to find out how to enable remote connections), or some firewall rule on your machine is preventing other machines from connecting to the instance of SQL Server Express, so I'd open Windows Firewall and allow inbound traffic on the port that SQL Server Express is listening on, or (better) move the SQL Server from your local machine to a dedicated development server.