Look, I'm working and doing tests with Access databases in Visual Basic.
I created an access database, and place it in the bin / debug folder of the project. Without assigning a password , it connects sucesfully with the database ... but when I encrypt the database (or put a password to the database with exclusively mode), my connection fails:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim tabla As DataTable = New DataTable
Dim ds As DataSet = New DataSet
Dim conexion As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=soq.accdb;Persist Security Info=False;Jet OLEDB:Database Password=mypassword;")
Try
conexion.Open()
MsgBox("Estoy operando.")
Catch ex As Exception
MsgBox("No ando haciendo eso")
End Try
conexion.Close()
End Sub
Whats the problem here?? I wrote something wrong??? (I got Microsoft Access 2013)
Okay guys, i found the solution!
The encryption method of Microsoft Access 2013 dont works properly. So my solution was simple: Use the encryption method of the 2007 version, and done!
Thanks all!
Related
Hi all I'm having trouble with regards to opening my connection on my mysql database on xampp. I'm not quite sure about the issue here. But please do correct me if I'm wrong, is there a problem with my connectionstring script or does Visual Studio 2019 handle it differently now compared to it's previous versions. I've tried removing the "con.Open()" line. but the problem with this is I can't seem to even be able to insert some data into my databse without the "con.Open()" line
here's the code by the way.
Module Module1
Public con As New MySqlConnection
Public cmd As New MySqlCommand
Sub openCon()
con.ConnectionString = "server=localhost; username=admin; password=; database=db_tutorial"
con.Open()
End Sub
End Module
here's an image of the error by the way.
I'm having a great deal of trouble finding code examples to connect a VB.net client application I am writing to a MYSQL5 database. I am trying to access a database I created through WAMP and phpMyAdmin.
where on the internet is a simple example of a programmatic implementation of an object I can use to connect these two seemingly un-connectable entities?
Just to make it a bit clearer:
I have a DB made through phpMyAdmin called: test
within the db is a table: sys_users
within the table are: user_ID (pk), user_name, user_password
simply looking to connect VB.net to test and query the table sys_users, returning a boolean if they exist. From there, I can figure out the rest of my solution for my program dealing with other tables and data.
thanks for any help in this.
Imports MySql.Data.MySqlClient
Imports System.Data.SqlClient
Public Class login
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim strConStr As String = "Data Source=localhost;uid=********;pwd=********;database=********"
Dim conn As MySqlConnection
conn = New MySqlConnection(strConStr)
MsgBox(conn.ConnectionString.ToString)
Try
conn.Open()
MessageBox.Show("Connection Opened Successfully")
conn.Close()
Catch myerror As MySqlException
MessageBox.Show("Error Connecting to Database: " & myerror.Message)
Finally
conn.Dispose()
End Try
End Sub
End Class
Yes, this was a problem for someone else, but the solution seems to work so far. As for the Password validation etc, I will most definitely make use of it. All I needed guys, thanks.
Good morning,
After watching numerous online tutorials and reading the Documentation, I decided to get hands on with the Crystal Reports for Visual Studio runtime. It is my understanding that the SAP Crystal Reports runtime doesn't natively support connections to a MySQL DB so I believe I've done everything correctly to pull the DB records into a Dataset object. I can see the records in the Dataset and they match what's in the Database. Unfortunately, when I run a preview of the report everything is "gibberish" except for the Date fields.
I'm stumped and don't know what to do now, any assistance would be greatly appreciated. Screenshots below show the records from the Dataset as well as the Report preview.
By the way, the Collation on the server and table are both set to "Latin1 - Default Collation" - not sure if that makes any difference.
IMAGE #1: VIEW OF DATASET RECORDS
Click here for a larger image: https://dl.dropbox.com/u/55174425/Dataset%20Records.jpg
IMAGE #2: DESIGN VIEW OF REPORT
Click here for a larger image: https://dl.dropbox.com/u/55174425/Design%20View%20of%20Report.jpg
IMAGE #3: PREVIEW OF REPORT
Click here for a larger image: https://dl.dropbox.com/u/55174425/Preview%20of%20Report.jpg
Hello SO,
I managed to answer my own question and decided to share my answer in case somebody out there runs into this same problem.
Well, it's not so much a problem as it is the actual way the Crystal Reports for Visual Studio runtime is supposed to work (at least when it comes to MySQL). What I didn't realize was that, because the CR runtime for VS didn't support a native connection to a MySQL database, it was necessary to use Visual Studio to create a Server Connection using the .Net Connector (which is made available when you install the Connector).
Once the server connection was made, I was then able to create a DataSet and populate it with the records from the DB. Unfortunately, what I didn't realize was that this dataset simply allows for the selection of the fields/columns necessary for the designing of the report (.rpt file). Now, here's where my "gibberish" problem was. In fact, I discovered that the CR runtime purposefully uses random text/characters when you're designing the report and if you preview the report you will see this. Also, if you debug the application you will get a blank report with only the column headers.
The solution to this is to programatically query the DB, create and fill a DataTable and assign it to a new instance of the report you just created as its datasource. And viola, the report now shows the information I was looking for. So, here's the code I ended up using at run-time in order to get my report to display the data I was looking for:
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
'Define the MySQL Connection String.
Dim myConnectionString As String = "Server=server_address;Port=3306;Uid=user_id;Password=password;Database=schema_name;"
'Create a new MySqlConnection object and assign the Connection String to it.
Dim dbConn As New MySqlConnection(myConnectionString)
'Define your Query.
Dim dbQuery As String = "SELECT * FROM users"
'Create a new MySqlDataAdapter object and assign the Query and Connection String objects to it.
Dim dbAdapter As New MySqlDataAdapter(dbQuery, dbConn)
'Create a new DataTable object and fill it with the contents of the MySqlDataAdapter object.
Dim dbTable As New DataTable
dbAdapter.Fill(dbTable)
'Create a new instance of the report you previously designed and set its DataSource to the DataTable.
Dim report As New rptUserList
report.SetDataSource(dbTable)
'Set the ReportSource of the CrystalReportViewer control to your report.
CrystalReportViewer1.ReportSource = report
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
I have a project in Visual Studio 2008 and there is a working data connection to a MySQL database. In other words, I can query the db directly from Visual Studio and it will display the results.
I've tried a couple of approaches that I found online for writing a connection string and accessing the db, but no luck yet.
All I'm trying to do is code a button to query the db and then reset the text property of a label/textbox to display the results based upon another label/textbox value.
The pseudo-code I am imagining is something like this:
Private Sub query_submit_button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles query_submit_button.Click
result_textbox.Text = SELECT field FROM table WHERE otherfield = key_textbox.Text
End Sub
I didn't see any related questions posted on SO - forgive me if I missed one that already exists and this is a dupe.
What is the correct way to accomplish this?
EDIT
Using MySQL 5.1
You can download the ODBC Provider and then reference, import, and use it to query the database through a ODBCCommand instance.
'Put this at the very top of your .VB file...
Imports System.Data.ODBC
'Put this in some method in your code when you are ready to query the DB...
Using connection As New OdbcConnection(connectionString)
Dim command As New OdbcCommand(strSqlQuery, connection)
connection.Open()
result_textbox.Text = command.ExecuteScalar.ToString
End Using
i used DaMartyr's answer to get 99% there, but needed to add this declaration:
Dim connectionString As String = "driver={MySQL ODBC 5.1 Driver};server=SERVER;uid=USERID;pwd=PASSWORD;database=DATABASE"
just replace the SERVER, USERID, PASSWORD, & DATABASE with your personal settings
I need to move my Sql Server CE database into MS Access, so my users who are familiar with Access can run queries on the data. Is there a free way to do that?
Thanks!
David
You have two options, you can either import the data into access or link the tables in access so the data stays in SQL CE and is just referenced by access.
I don’t think access can import it directly so you will have to make an ODBC connection to your CE file using the ODNC admin program in windows. Once you have done that you can move onto the next step
On the file menu go to get external data and then either import or link depending on what option you want, on the next dialog box select ODBC databases as the file type and select the ODBC connection you just made.
Follow the on screen prompts from there and Roberts your mothers brother
EDIT:
Sorry yes I did mean ODBC, my finger must have slipped on the keyboard. Anyway Yes it looks like the ODBC driver does not exist however a OLEDB driver does so you could open up the database in code using ADO and either manipulate it there or loop through each table and insert it into an access table you created earlier. Here is some code showing how to open a SQL CE recordset in VBA
Sub test()
Dim pConn As ADODB.Connection
Dim pRS As ADODB.Recordset
Set pConn = New ADODB.Connection
Dim cmd As New ADODB.Command
Set pRS = New ADODB.Recordset
' For 3.0 use PROVIDER=Microsoft.SQLSERVER.MOBILE.OLEDB.3.0
pConn.ConnectionString =
"PROVIDER=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source=C:\Northwind.sdf"
pConn.Open
cmd.ActiveConnection = pConn
cmd.CommandText = "SELECT * FROM Products"
Set pRS = cmd.Execute
' Open the recordset
While Not pRS.EOF
Debug.Print pRS(0)
Debug.Print pRS(1)
pRS.MoveNext
Wend
End Sub