Get DB file name - ms-access

Is there any SQL statement who retrieve the file name for a .mdb DB ?
There is something similar in SQLite: SELECT file FROM pragma_database_list WHERE name='main'
I need the same thing, but for Microsoft Access Database.

You need VBA for this:
DbName = CurrentProject.Name
There is no SQL expression/function.

Related

Data Migration from MS Access to Oracle-sql Developer using ODBC link

I'm migrating data from Microsoft Access 2013 to Oracle-SQL Developer(Oracle client 12.1). I'm using ODBC link, I can migrate my tables but the conversion of the data types isn't correct. In fact, all the data types re converted to VARCHAR2(eg. NUMBER(Access)becomes VARCHAR2(Oracle)).
How can I fix it ? Is there any way to convert types explicitly ?
Thank you
You may be able to do it in two steps, first migrating to MS SQL server. You can use the free Express Edition and the free Access to MS SQL migration tool which allows you to manually map MS Access types to MS SQL Server types. It should be fairly easy to find out what MS SQL Server types migrate to in Oracle-SQL so you can make the necessary mappings on the fist step.
There are several approaches.
One approach is to build the table structure in Oracle (use Oracle design tools). You then link to that oracle table in Access.
You can now run a append query in Access to send the table from Access to Oracle. The result will be data type mappings of your choice. And you can even build such a append query with the Access query bulder.
Another approach is to send the data from Access to Oracle. You don’t mention now how you are doing this. But, most data types will and do get translated correctly if you use the transfer database command with this format:
Sub SendToSQL()
Dim strLocalTable As String
Dim strSQLTable As String
Dim strSQLDataBase As String
strSQLDataBase = "test3"
strLocalTable = "tblFood"
strSQLTable = "tblFood"
Dim strODBC As String
strODBC = "ODBC;DRIVER=SQL Server;SERVER=ALBERTKALLAL-PC\SQLEXPRESS;Trusted_Connection=Yes;DATABASE="
strODBC = strODBC & strSQLDataBase
DoCmd.TransferDatabase acExport, "ODBC Database", _
strODBC, acTable, strLocalTable, strSQLTable
End Sub
The above should send + create the table in Oracle, and you should retain “most” of the correct data types when you do the above.
Of course the above example uses a SQL server connection string, and you would of course replace the above connection string with a oracle one.

Can't pass in variables into OLE DB source command

I am creating a SSIS package that involves a where clause as:
WHERE effectiveDate >= #effectiveDate
Therefore, I defined #effectiveDate at the package level so that I can pass in value from a sql command using a different connection.
At the OLE DB source, I selected 'SQL command', and put the code as
Select ... FROM ...
WHERE effectiveDate >= ?
When I click on the 'parameters', an error appears:
'Parameters cannot be extracted from the SQL command. blablabla... use "SQL command from variable"...'
I am trying to avoid using SQL command from variable and try to locate the problem since I should be able to pass in variable.
Can anyone help? Thanks a lot!!
When building an OleDbCommand, you should actually name the parameter as the package is expecting, such as
OleDbCommand cmd = new OleDbCommand( "select ... from... where... eff > #yourPkgPameterName");
cmd.Parameters.AddWithValue( "#yourPkgPameterName", whateverValueToSend );
It's been a while for SQL-based parameters and don't remember if the AddWithValue() method is expecting the "#" or not... may need to try without it if it fails.

How to upload text file data into sqlserver database using c#?

my text file like this.
name :Settings, id :1, preference :Mail
name:test ,id:2,preference :testMail
I need to read that textfile and placed that as records in sqlserver database.
name id preference
settings 1 Mail
test 2 testMail
How to parse that textfile like as above .please tell me
Use SQL Management Studio 'Import Data' task, that generates an SSIS package.
Use SQLbulkcopy method of C#.net to insert textfile data into sql server table.
Check this LINK

import database dump to mysql using visual foxpro

I used leaves stru2mysql.prg and vfp2mysql_upload.prg to create a .sql dump file from DBF's. I connect to mysql database from vfp using ODBC.I KNOW how upload the sql dump file but i need to automate the whole process i.e after creating the dump file,my visual foxpro program can upload the dump file without a third party(automatically). I thought of using the source command but that needs to be run in mysql prompt.The assumption here is that my end users dont know how to import(which most of them dont).Please advice on how i can automate importation of sql file to mysql database.thank you
I think what you are looking for are the various SQL* functions in Foxpro. See the VFP help or MSDN on SQLCONNECT (or SQLSTRINGCONNECT), SQLEXEC, and SQLDISCONNECT functions to get you started. Microsoft provided good examples on each in the documentation.
You may also want to use FILETOSTR to get the output from Leafe's programs into a string for the SQLEXEC function.
Here's the steps I use to take data from a Visual FoxPro Database and upload to a MySql Database. These are all put into a custom method on a form, which is fired by a command button. For example the method would be 'uploadnewdata' and I pass parameters for whichever data tables I need
1) Connect to the Server - I use MySql ODBC
2) Validate the user (this uses a SQLEXEC to pull the correct matching record for a users tables
IF M.WorkingDatabase<>-1
nRetVal=SQLEXEC(m.WorkingDatabase,"SELECT * FROM users", "csrUsersOnServer")
SELECT csrUsersOnServer
SELECT userid,FROM csrUsersOnServer;
WHERE ALLTRIM(UPPER(userid))=ALLTRIM(UPPER(lcRanchUser));
AND ALLTRIM(UPPER(lcPassWord))=ALLTRIM(UPPER(lchPassWord));
INTO CURSOR ValidUsers
IF _TALLY>=1
ELSE
=MESSAGEBOX("Your Premise ID Does Not Match Any Records On The Server","System Message")
RETURN 0
ENDIF
ELSE
=MESSAGEBOX("Unable To Connect To Your Database", "System Message")
RETURN 0
ENDIF
3) Once that is successful I create my base cursor (this is the one I'm sending from)
4) I then loop through that cursor creating variable for the values in the fields
5) then using the SQLEXEC, and INSERT INTO, I update each record
6) once the program is finished processing the cursor, it generates a messagebox with the 'finished' message and control returns to the form.
All the user has to do, is select the starting table and enter their login information

Dump MySQL database with Qt

I have this slot:
void Managment::dbExportTriggered()
{
save = QFileDialog::getSaveFileName(this, trUtf8("Export db"),
QDir::currentPath() + "Backup/",
trUtf8("Dumped database (*.sql)"));
sqlQuery = "SELECT * INTO OUTFILE '" + save + ".sql' FROM Users, Data";
//QMessageBox::critical(0, trUtf8("query dump"), QString::number(query.exec(sqlQuery)));
query.exec(sqlQuery);
}
And I have this query:
sqlQuery = "SELECT * INTO OUTFILE " + save + " FROM Users, Data";
I execute normally but no dumped file appear, the backup directory has the right permission, the dumped database must be in client.
UPDATE:
After a search I found that the INTO OUTFILE query will dump database in the server not in the client as I was thought, so my question now how can I dump database in remote MySQL server, any quick methods with out any external tools like mysqldump client.
SELECT ... INTO OUTFILE creates a file on the MySQL server machine, with permissions matching whoever the MySQL server runs as. Unless you have root access on the MySQL server to retrieve the file that you're exporting, SELECT ... INTO OUTFILE is unlikely to do what you want.
In fact, I think I'd go so far as to say that if you're trying to use SELECT ... INTO OUTFILE from a GUI client, you're probably taking the wrong approach to your problem.
Just an idea: Another approach is to call mysqldump with QProcess. With some google-fu this seems to be an example:
..
if (allDatabases->isChecked()) {
arguments << "--all-databases";
} else {
arguments << "--databases";
foreach(QListWidgetItem *item, databasesList->selectedItems())
arguments << item->text();
}
proc->setReadChannel(QProcess::StandardOutput);
QApplication::setOverrideCursor(Qt::WaitCursor);
proc->start("mysqldump", arguments);
..
Thus, you can also add some parameters to dump only a specific table.
Edit:
Just note from the mysql doc on the SELECT ... INTO OUTFILE statement:
If you want to create the resulting
file on some other host than the
server host, you normally cannot use
SELECT ... INTO OUTFILE since there is
no way to write a path to the file
relative to the server host's file
system.
Thus you must roll your own, or you can use mysql -e as suggested by the above documentation.
Did you dump/print save to check it's valid? Does currentPath() return a trailung "/"?
Could there be difference between the path as seen by your client program and as (to be) seen by the server?
Does the user have the necessary privileges (file privilege for sure, maybe more)
Can't you get an error message from the log?
Are you getting any errors running the sql statement?
I notice that you're concatenating the filename into the SQL query without surrounding it by quotation marks. Your code will yield something like
SELECT * INTO OUTFILE /path/to/somewhere FROM Users, Data
but the MySQL documentation says it wants something like
SELECT * INTO OUTFILE '/path/to/somewhere' FROM Users, Data
Also keep the following in mind:
The file is created on the server host, so you must have the FILE privilege to use this syntax. file_name cannot be an existing file, which among other things prevents files such as /etc/passwd and database tables from being destroyed.
If you're looking on your client, you won't see the file there, even if the operation succeeds.