Connection string for Access 2010 - ms-access

I want to connect to the access 2010 database from excel.I am using VBA.I wrote the connection string as
Public objCon As New ADODB.Connection
objCon.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ActiveWorkbook.Path & _
"\asset_database.accdb;ACE OLEDB:Database Password=password;"
But it is giving the error "could not find installable ISAM".What is this error?

Oddly enough, it is Jet OLEDB Password, not ACE:
objCon.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ActiveWorkbook.Path _
& "\asset_database.accdb;Jet OLEDB:Database Password=password;"
See: http://www.connectionstrings.com/access-2007

Try "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ActiveWorkbook.Path & "\asset_database.accdb;JET OLEDB:Database Password=password;"

If you have Access installed, or you install the Access Database Engine on the workstation that has the Excel spreadsheet open, then you don't need to create an OLEDB connection; you can just open a database object as follows:
dim db as database
set db=opendatabase("c:\db path\my db.accdb")

Related

How To Insert Data in Hosting Database Using VB.NET

I've a Hosting that contains mysql database, and i simply want to insert data into that database but using VB.NET.
Ex :
There's a Textbox and a button, when click on button is performed the value from that textbox have to be inserted in database of hosting.
What service or functions should i use??
Dim Conn As New ADODB.Connection
Conn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=" & server & ";DATABASE=" & database & ";UID=" & user & ";PWD=" & pass & ";PORT=" & port & ";"
Conn.Open()
Conn.Execute("insert into tblname (fld1,fld2) values('"& textVal &"',"& numericVal &")")
Conn.Close()
Conn = Nothing
Paste in .vb file and edit connectionstring & insert string.
Good luck..

Connecting Ms Access Db to Mysql through Vba

I have been trying to connect mysql database to ms Access but no result.I don't think personally I am using the DAo.Connection and the workspace properly. I keep on getting the 3001 connection error when I set mySqlCon. I guess my arguments are not properly set but I was following an example from here.
Function connectingMySql()
Dim mySqlCon As Dao.Connection
Dim wrkODBC As Workspace
Set wrkODBC = CreateWorkspace("newODBCWorkspace", "admin", "", dbUseODBC)
Set mySqlCon = wrkODBC.OpenConnection("connection1", , , "DRIVER={MYSQL ODBC 5.1 DRIVER};" _
& "SERVER=testserver.com;port=3306;" _
& "DATABASE=test;" _
& "USER=root;" _
& "PASSWORD=pass;" _
& "Option=3;")
End Function
More infos:
Running Ms Access 2003
This MSDN page says that using dbUseODBC will cause a runtime error.
ODBCDirect workspaces are not supported in Microsoft Access 2010. Setting the type argument to dbUseODBC will result in a run-time error. Use ADO if you want to access external data sources without using the Microsoft Access database engine.
Try Set wrkODBC = CreateWorkspace("newODBCWorkspace", "admin", "")
After much struggle, I fixed it. Basically my arguments where wrong. Now I am getting a connection Error, which means the argument error has been fixed.
Function connectingMySql()
Dim mySqlCon As Dao.Connection
Dim wrkODBC As Workspace
Set wrkODBC = CreateWorkspace("newODBCWorkspace", "admin", "", dbUseODBC)
Set mySqlCon = wrkODBC.OpenConnection("DRIVER={MYSQL ODBC 5.1 DRIVER};" _
& "SERVER=testserver.com;port=3306;" _
& "DATABASE=test;" _
& "USER=root;" _
& "PASSWORD=pass;" _
& "Option=3;")
End Function

How do I setup an ADODB connection to SQL Server 2008 in Microsoft Access 2010?

I just installed SQL Server 2008 on my laptop. I also have Microsoft Access 2010 installed. Using VBA, I am trying to create an ADODB connection to my own database on SQL Server but I'm having trouble finding the right line of code:
When I use this below, it doesn't work.
The name of my computer is LAPTOPX and the database is HomeSQL.
I am sure it's super easy but since I'm just starting out I can't seem to find the right way to ask the question.
Thanks!
Dim DBCONT As Object
Set DBCONT = CreateObject("ADODB.Connection")
Dim strDbPath As String
strDbPath = "LAPTOPX/HomeSQL"
Dim sConn As String
sConn = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source =" & strDbPath & ";" & _
"Jet OLEDB:Engine Type=5;" & _
"Persist Security Info=False;"
DBCONT.Open sConn
First, you need to make sure SQL Native Client is instaled. Reference
SQL Server 2008
Standard security
Provider=SQLNCLI10;Server=myServerAddress;Database=myDataBase;Uid=myUsername;
Pwd=myPassword;
Trusted connection
Provider=SQLNCLI10;Server=myServerAddress;Database=myDataBase;
Trusted_Connection=yes;
Connecting to an SQL Server instance
The syntax of specifying the server instance in the value of the server key is the same for all connection strings for SQL Server.
Provider=SQLNCLI10;Server=myServerName\theInstanceName;Database=myDataBase;
Trusted_Connection=yes;
Source
Dim conn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim sConnString As String
Dim recordsAffected as Long
'Create connection string
sConnString = "Provider=sqloledb; Server=LAPTOPX; Database=HomeSQL; Trusted_Connection=True;"
'Open connection and execute
conn.Open sConnString
'Do your query
With cmd
.ActiveConnection = conn
.CommandType = adCmdText
.CommandText = "Select ...;"
.Execute recordsAffected 'Includes a return parameter to capture the number of records affected
End With
Debug.Print recordsAffected 'Check whether any records were inserted
'Clean up
If CBool(conn.State And adStateOpen) Then conn.Close
Set cmd = Nothing
Set conn = Nothing
This connetion string works under Excel VBA. In MsAccess also should.
dbName = "test" 'your database name
dbFilePath = "C:\db.mdf" 'your path to db file
connStr = "Driver={SQL Server native Client 11.0};" & _
"Server=(LocalDB)\v11.0;" & _
"AttachDBFileName=" & dbFilePath & ";" & _
"Database=" & dbName & ";" & _
"Trusted_Connection=Yes"
Full solution: http://straightitsolutions.blogspot.com/2014/12/how-to-connect-to-sql-server-local.html

Error while connecting to Access database through Excel 2010

I am trying to retrieve data from an access database on my C drive and i am getting the following error:
"Cannot start your application. The workgroup information file is missing or opened exclusively by another user."
the debugger shows the error in the following piece of code:
MyConnObj.Open _
"Provider = Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\<database>.mdb;" & _
"User ID=<username>;" & _
"Password=<pass>;"
how do i fix this error?
I have the following definitions:
Dim MyConnObj As New ADODB.Connection 'ADODB Connection Object
Dim myRecSet As New ADODB.Recordset 'Recordset Object
Dim sqlStr As String ' String variable to store sql command
Not sure, but that error means that you need to specify a Workgroup (system database) file.
Try to add this to your connection
MyConnObj.Open _
"Provider = Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\<database>.mdb;" & _
"Jet OLEDB:System Database=<path to system.mdw with information on username/pass>;" & _
"User ID=<username>;" & _
"Password=<pass>;"
in alternative, if your access mdb is not protected with a system.mdw file, you could try to remove the "User ID" and "Password" parts from the connection string.

Excel VBA: writing to mysql database

I would like to write a macro in Excel that will write to a mysql database. Can someone please get me started on this?
You can connect to MySQL with a connection string and ADO:
''http://support.microsoft.com/kb/246335
Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
strCon = "Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=MyDB;" _
& "User=root;Password=pw;Option=3;"
cn.Open strCon
You can also use DSN with a connection to Excel using the Jet driver:
Dim cn As ADODB.Connection
''Not the best way to get the name, just convenient for notes
strFile = Workbooks(1).FullName
strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFile _
& ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";"
Set cn = CreateObject("ADODB.Connection")
''For this to work, you must create a DSN and use the name in place of
''DSNName
strSQL = "INSERT INTO [ODBC;DSN=DSNName;].NameOfMySQLTable " _
& "Select AnyField As NameOfMySQLField FROM [Sheet1$];"
cn.Execute strSQL
Writing to a mysql database is no different to writing to any other database.
You'd create an ADODB.Connection object, .Open it with an appropriate connection string and use the .Execute method (or ADODB.Command) to execute sql.
See http://msdn.microsoft.com/en-us/library/ms807027.aspx for more information.
You'd have to a have a mysql access driver installed (ODBC or OLEDB) and reference the Microsoft ActiveX Data Objects 2.8 from your vba project.