dBaseIV file creation from SQL Server 2016 database - sql-server-2016

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

Related

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 to insert foxpro 6 table to visual studio 2017?

Recently I want to renew my old application witch is use foxpro 6 to wrote. Now i want to use VB.net to do a new one. The reason behind is that my project is a POS system for my uncle's shop. since the PC is too old that maybe broken anytime, I need to renew it and compatible with Windows 10 because the new PC is using Windows 10. So that's why I need to make a new app But when i use the link services(data source>add new data source) in Visual Studio, it show my table is blank which is wrong, My table is full of data. so how can i successfully link the table to visual studio?
Connection string Dsn=inventory
PS:i use the right odbc driver and test it multiple times and stand still.
Thank You all.
Use VFPOLEDB for connection. With VFPOLEDB, you would simply use an OleDbConnection with a connection string like:
new OleDbConnection("Provider=VFPOLEDB;Data Source=c:\your data folder")
Also check Tom Brother's LinqToVFP, VFP EF Provider and others on codeplex.
IMHO, using windows 10 is not a good reason to rewrite a VFP application in VB.Net. Anyway if you want to do that, then why wouldn't you also change your database backend to something else like postgreSQL, MySQL, SQL Server, ... etc.
I found the solution that you can use code instead of wizard to connect the FoxPro table, here's the solution.
Use a connection string to connect the table first, than set a DataAdapter and DataSet for the table, Finally fill the DataAdapter and put it into the DataGridView.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim connectionString As String = "provider=vfpoledb.1;data source=your location"
Dim myConnection As New System.Data.OleDb.OleDbConnection(connectionString)
myConnection.Open()
Dim dataAdapter As New OleDbDataAdapter("FoxPro SQL cmd", myConnection)
Dim dataSet As DataSet = New DataSet
dataAdapter.Fill(dataSet, "Q")
DataGridView1.DataSource = dataSet.Tables("Q")
End Sub
Hope this can help.

Crystal Reports failed to open the connection

I am developing a desktop software which is creating proposals and invoices. I am storing my database (MySql) in a remote server. Everything is working perfectly fine in my PC which i am using for coding.
On client machine I can add,update and delete records without any problem. But when i try to open a record in then I am facing with an error below.
I was created the report in VB.NET but when I face with the error than I opened the rpt file in Crystal Reports XI Release 2 and updated data source location, verified database and save the file. Some part of my code is :
ElseIf Me.Text = "Tekliflere Gözat" Then
Form16.Text = "Teklif Detayları:"
Dim strReportPath As String
Dim rptDoc As CrystalDecisions.CrystalReports.Engine.ReportDocument
strReportPath = My.Application.Info.DirectoryPath & "\Teklif.rpt"
rptDoc = New ReportDocument
rptDoc.Load(strReportPath)
rptDoc.SetDatabaseLogon("USER_NAME", "PASSWORD", "SERVER_IP", "DB_NAME")
Form16.CrystalReportViewer1.ReportSource = rptDoc
Form16.CrystalReportViewer1.SelectionFormula = "{teklif1.teklifno} =" & ListView1.SelectedItems(0).Text
Form16.CrystalReportViewer1.Refresh()
Form16.CrystalReportViewer1.RefreshReport()
Form16.Show()
Me.Close()
Could you please advise.
Thank you.
Regards
Oguz
I've found the solution. But first have to look at the casue. While connecting to a remote database via my software everthing is working fine. But when I was designing a report in CR, I created a connection in database expert menu. So that means locally I am describing to CR that where and how to connect. But when I install my software with all necessery components to the client machine CR report files searching the connection criteria and as a matter of course it can not find it in client machine.
So the solution is to install Mysql ODBC Connector to the client machine and configure it with the same settings in my PC. Or as an alternative solution, define all connection and database settings programatically in your code.
Hope this helps.

connection to Pervasive database slow

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!

How to release MS Access LDB lock file after created it

sorry for long text.
Problem: I have difficulty in removing the LDB generated by the "CREATE" method of ADOX in the following code segment. Please provides some hints/pointers to the solutions, and thanks.
Aims: Create (on the fly) a new access database and then export data (says Arena modules) to that newly created database.
Expected: The newly created access database should be able to be used by some external operations, say Access.exe, after the end of the subroutine and without exiting the current VB program.
I tested that the "Arena code" do nothing about the create/release of the ldb file.
I tested the "Exclusive Mode" in connection string, but the access file is still locked by the vb program.
I tested under both inside the VB environment, and directly invoke the generated from Explorer, and same results.
Other database formats is not the options to me. (due to Arena export limit)
It is not a web app.
Code:
Sub Method1()
Dim logs As New System.Collections.Generic.List(Of String)
Dim arenaApp As Arena.Application = Nothing
Try
logs.Add("Creating access database")
Try
Dim cat As New ADOX.Catalog
cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=new.mdb;Jet OLEDB:Engine Type=5")
cat = Nothing
Catch ex As Exception
logs.Add(ex.Message)
logs.Add(ex.StackTrace)
Finally
logs.Add("End creating access database")
End Try
'Opening Arena model"
arenaApp = New Arena.Application()
arenaApp.Models.Open(fileName)
arenaApp.ActiveModel.ExportModules("", "new.mdb", "TableName", "", Arena.smExportType.smExportAll)
Catch ex As Exception
logs.Add(ex.Message)
logs.Add(ex.StackTrace)
Finally
...
End Try
End Sub
Platform:
Windows 7 64bit, Office 2010 (32)
VB 2010 express
Lib: MS ADO Ext. 2.8 for DDL and Security
What about closing the mdb after creation, then reopening it ?
I am not a VS expert, but in Access, many things in "Design mode" put the mdb in Exclusive mode...and you can't switch back without closing it first i suspect.
If you want to create a database, its probably simpler to PInvoke SQLConfigDataSource. Then you can connect to it via ADODB, ADO.NET or your VB.NET data access methodology of choice.
I don't have an example of doing it in VB.NET, but this C# class and this powershell script demonstrate how to call the function.
I know it's an old question. I encountered exactly the same issue today. Some comments ask why use ADOX, that's because first, it's from legacy code, and second, I didn't find any other ways to dynamically create mdb file.
In VB6, whenever you set adox = Nothing, this com object will be released immediately and so is the ldb file.
In .Net, you have to rely on GC to collect the adox before ldb file is unlocked.
So, I made the following trick. I know it's ugly, but I didn't find any other ways, and at least my trick worked.
Dim t As New Thread(
Sub
'All adox code should be here
'....
'....
adox = Nothing
End Sub
)
t.Start()
t.Join()
t = Nothing
GC.Collect()
Sleep(50)