Getting names of Access database tables with Matlab - ms-access

I'm trying to get a listing of all tables in an Access database using Matlab.
I'm so far using an actxobject and can successfull run queries against the database, but all methods I've read here have failed.
I consistently get the error message 'No read permission on MSysObjects'. The query runs fine within the Access-program, but the implementation of my program does not allow me to store the query there.
So, my question is: Is there any way to list all the tables of an Access database through Matlab?

Consider this code:
conn = actxserver('ADODB.Connection');
connString = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Nwind.mdb';
conn.Open(connString);
rs = conn.OpenSchema('adSchemaTables').GetRows;
tableNames = rs(3, ismember(rs(4,:),'TABLE') );
and the result is:
>> tableNames'
ans =
'Categories'
'Customers'
'Employees'
'Order Details'
'Orders'
'Products'
'Shippers'
'Suppliers'

Related

How to display all tables in database using vb.net with mySQL xampp?

I am new with mySQL with xampp and VB.net connection and i try to research my question but all of them i cant get it could you please explain and correct my code down below
Try
openCon() ''connection
mysqlCommand.Connection = con
mysqlCommand.CommandText = "SHOW TABLES;"
mysqlAdapter.SelectCommand = mysqlCommand
data.Clear() ''dataset
mysqlAdapter.Fill(data)
con.Close()
ListBox1.DataSource = data.Tables(0)
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
i get nothing when im run this code.
Your code to retrieve the table names is correct. The error is in the assignement to the ListBox datasource without specifying which column of Table(0) should be used to display the lines in the ListBox.
Without setting the DisplayMember property to the name of the column, the Listbox could only display the name of the object that you bind. This object is DataRowView.
The command SHOW TABLES when used to fill a DataAdapter creates a table with a single column and the name of this column is Tables_of_<databasename> but you can also use an indexing approach without giving the exact name of the column
Try
openCon()
mysqlCommand.Connection = con
mysqlCommand.CommandText = "SHOW TABLES;"
mysqlAdapter.SelectCommand = mysqlCommand
data.Clear()
mysqlAdapter.Fill(data)
con.Close()
'' Use whatever is the name of the first column in table returned
ListBox1.DisplayMember = data.Tables(0).Columns(0).ColumnName
ListBox1.DataSource = data.Tables(0)
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
To complete my answer I suggest you to avoid using global variables for the connection, commands and dataadapters. You could only find yourself in trouble when you forget to clear the previous usage of these objects. And the connection is absolutely not the right type of object to keep global. Use the Using statement to create a local connection and destroy it when done.
Finally, remember that SHOW TABLES is a command understood only by MySql. If you ever need to use this same code with a different database you should change that line and use the more standardized query
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = #yourDBNameParameter

Method has no supported translation to SQL(Linq to Sql)

After I execute a query on the database, and try to print the result of that execution, I got this error:
Method has no supported translation to SQL.
My code:
Table<User> users = DAL.DALConnection.Database.GetTable<User>();
var query = from user in users
where user.Get_UserName().ToString() == username
select user;
foreach (User user in query)
Console.WriteLine(user);
Is Get_UserName() a C# function you've written in your code? If so, the error coming back makes sense, because SQL Server doesn't know about that function.
Instead, you would probably want to do something like where user.username == username, assuming your table has a username field.

RDCOMClient package: How to read data from a query

I am currently on the issue to connect to a Cube with R using .COM objects, to then gathering data from the Cube via mdx-queries. As in my previous question described (see link below), I can now connect to the cube with the help of the RDCOMClient package and R version 3.3.1, and can also send queries to the cube.
Moreover, when tracing my connection with the SQL Server Profiler, I can see it connected correctly + I also see that my query is executed without errors.
However, I have no idea how I can obtain my data inside R. I save the query result in the variable results, but I am unable to do anything with it. Can you help me display my query results in R please?
.
Connection + Query Code:
conn = COMCreate("ADODB.Connection")
connStr = 'my connection string'
conn[["ConnectionString"]] = connStr
conn$Open()
conn[["State"]]
query = 'some query. 100% correct, tested with other tools'
results = conn$Execute(query)
.
Information for the results variable: (Code, followed by the Output)
names = slotNames(results)
names
[1] "ref"
.
slot(results,names[1])
pointer: 0x0000000015d63c60
.
str(results)
Formal class 'COMIDispatch' [package "RDCOMClient"] with 1 slot
..# ref:
.
class(results)
[1] "COMIDispatch"
attr(,"package")
[1] "RDCOMClient"
.
attributes(results)
$ref
$class
[1] "COMIDispatch"
attr(,"package")
[1] "RDCOMClient"
.
Thanks for helping :-)
.
Previous question: R & COM-Objects: How to connect to a OLAP cube on Windows
Consider using ADO's GetRows() method which returns records of a recordset in a nested VBA array which would translate into a nested R list. Currently, you only retrieve the recordset object.
results = conn$Execute(query)$GetRows()

How to update a row in a MySQL database using Ruby's Sequel toolkit?

This should be the simplest thing but for some reason it's eluding me completely.
I have a Sequel connection to a database named DB. It's using the Mysql2 engine if that's important.
I'm trying to update a single record in a table in the database. The short loop I'm using looks like this:
dataset = DB["SELECT post_id, message FROM xf_post WHERE message LIKE '%#{match}%'"]
dataset.each do |row|
new_message = process_message(row[:message])
# HERE IS WHERE I WANT TO UPDATE THE ROW IN THE DATABASE!
end
I've tried:
dataset.where('post_id = ?', row[:post_id]).update(message: new_message)
Which is what the Sequel cheat sheet recommends.
And:
DB["UPDATE xf_post SET message = ? WHERE post_id = ?", new_message, row[:post_id]]
Which should be raw SQL executed by the Sequel connector. Neither throws an error or outputs any error message (I'm using a logger with the Sequel connection). But both calls fail to update the records in the database. The data is unchanged when I query the database after running the code.
How can I make the update call function properly here?
Your problem is you are using a raw SQL dataset, so the where call isn't going to change the SQL, and update is just going to execute the raw SQL. Here's what you want to do:
dataset = DB[:xf_post].select(:post_id, :message).
where(Sequel.like(:message, "%#{match}%"))
That will make the where/update combination work.
Note that your original code has a trivial SQL injection vulnerability if match depends on user input, which this new code avoids. You may want to consider using Dataset#escape_like if you want to escape metacharacters inside match, otherwise if match depends on user input, it's possible for users to use very complex matching syntax that the database may execute slowly or not handle properly.
Note that the reason that
DB["UPDATE xf_post SET message = ? WHERE post_id = ?", new_message, row[:post_id]]
doesn't work is because it only creates a dataset, it doesn't execute it. You can actually call update on that dataset to run the query and return number of affected rows.

Cannot switch a connection string in LLBL Gen Pro

I have two databases with the same schema inside a Sql 2008 R2 Server, of which names are Database1 and Database2. I connected and performed queries on the Database1, and then changed to Database2 to fetch my entities using the following code
this.ConnectionString = "Server=TestServer; Database=Database2;Trusted_Connection=true";
using (IDataAccessAdapter adapter = new DataAccessAdapter(this.ConnectionString))
{
var entities = new EntityCollection<T>();
adapter.FetchEntityCollection(entities, null);
return entities;
}
(The connection string was set before executing the code).
I debugged the application and looked at the value of the connection string, it pointed to the Database2.
However, when I executed the above code, the result was return from the Database1. And if I looked at SQL Profiler, the statement was executed against Database1.
So, could anyone know what was going on? Why the query was executed against the Database1, not Database2.
PS: If I used the above connection string with plain ADO.NET, I was able to retrieve data from Database2.
Thanks in advance.
I have figured out what was going on. The reason was: by default LLBL Gen Pro uses fully qualified names like [database1].[dbo].[Customer] to access database objects, and the catalog is specified when generating entities. So you can't access objects just by changing the connection string.
Hence, to change to another database you have to override the default catalogue by using following code
var adapter= new DataAccessAdapter(ConnectionString, false,
CatalogNameUsage.ForceName, DbName)
{CommandTimeOut = TenMinutesTimeOut};
More information can be found at the following link