In my Visual Basic Application, I have an access database file that I am using. It shows up in the solution explorer window. Everything works great until I install. The database file doesn't go with the installation for some reason. I guess I need to edit the connection string during runtime, but I am not sure. I have not done anything like this before, and I cannot find the information about it.
If someone could send me to a tutorial or give a brief explanation of how to use an access database once the application has been installed.
When my program runs, it creates a directory in
User\App Data\Roaming\CreatedFolder\Resources\DatabaseFile.accdb
So how do I set this path without knowing the full path up to App Data?
You can use
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
or
Environment.GetEnvironmentVariable("APPDATA")
They both should return something similar to
C:\Users\Gord\AppData\Roaming
so you can build your connection string like this:
Dim dbPath = _
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & _
"\CreatedFolder\Resources\DatabaseFile.accdb"
Dim connStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dbPath
The way I would do this would be to:
Select Add New Data Source . . . from the Data Source window in Visual Studio
Select Database from the list that appears, and click next
Click next
In the Choose your data connection page of the wizard, click New connection
Choose Microsoft Access Database File from the listbox and click next
Choose a copy of the database file that is not in your directory and enter any login information
Click OK
Now Visual Studio will ask you:
The connection you selected uses a local data file that is not in the
current project. Would you like to copy the file to the project and
and modify the connection?
If you copy the data file to your project, it will be copied to the project's
output directory every time you run the application. Press F1 for
information on controlling this behavior.
Click "Yes," and Visual Studio will add the database to your project and make a connection string that points to the copied database.
Now you will probably want to save the connection string in App.Config so that you don't have to rebuild it every time you want to use the database. Most likely this will save a connection string that uses |DataDirectory|. Modify the contents of this page as you see fit.
Procede through the rest of the wizard and configure your database as you need it.
The wizard should configure the connection string and build information such that your application will work no matter where you take it.
EDIT - My connection string as it is saved in App.config looks like
<connectionStrings>
<add name="SOAccessDatabase.My.MySettings.Students_2000formatConnectionString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Students_2000format.mdb"
providerName="System.Data.OleDb" />
</connectionStrings>
I also have the database file's Build Action set to "Copy Always."
Related
I am a newbie and not also good in explaning but i will try my best I hope you understand so here it is. Im trying to create application.exe with ms access database at first it works login and searching but when i try to edit or enter another data using my application.exe this happen operation must use an updateable query but when im not using .exe app no problem show
This is the step by step That i do when executing my app. why did i include this maybe, I don't know and I'm not really sure that the cause of the problem is the way of my executing the application. By the way this is my connection string that I use
Public cn As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\DB_HR.accdb;Jet OLEDB:DATABASE PASSWORD=dbhr123;")
Step 1. I put my database the bin/debug
Then
Step 2. I add my data base Solution Explorer
Step 3.I go to the properties of my DB_HR.accdb by right cliking and change the Copy to output Directory to Copy if newer like this
Step 4. I build the windows app just like i do in this picture
Step 5.I change my app.manifest code requestedExecutionLevel level="asInvoker" uiAccess="false" into highestAvailable just like this
Step 6. I use Setup Wizad to create my executable application. and I add this Files and then I created a
shorcut for my WindowsApp1.exe just like i do in this picture then drag it into user's Desktop Then in the Build menu I click the batch build to create the .exe app
But the problem is still The same operation must use an updateable query
Can you help me please.What should I Do? Thanks in advance
I Found a solution. Try to check your App.config Solution Explorer and Open it.
If the code look like this then You should Add this code then save it.
Then try to execute your program.
I'm new to SSIS. I have a DataBase from which i'm getting the data. Suppose DB is the source and destination may be anything. (I tried DB to Excel and it worked fine)
In the source i have a custom query to get the data. I have written that in the properties.
Now i want to change it. I want to put it in some configuration file (xml file). i.e., i want to
get the query of the source from the xml file. How can i do this?
I'm a complete newbie trying the things. So please give your answer specifically.
UPDATE:
This is my package
I double clicked the OLE DB source. Now This is what i written there
I want to put the query (select id, age from emp where exp > 4), in a configuration(xml) file.
Create a package level variable for your query:
Change your source editor to use SQL command from variable (with appropriate variable) instead of SQL command:
Go to the SSIS menu and click "Package Configurations..." then click the checkbox to Enable package configurations, then click the "Add..." button.
... By default, it uses an XML Configuration file, which is probably easiest to work with. Specify a filename - the file extension is .dtsConfig. If the file doesn't exist on your machine, it will create one for you. Click Next.
Find your Variable, find the Value property for the variable, and check the box for it. Click Next.
Choose a name for your configuration. Click Done, then click Close in the Package configuration list, making a note of where on your file system you saved your configuration file.
Find the configuration file on your file system. Right-click and edit with an XML editor as needed.
I notice in VS2010's Tools > Options dialog, there is a section on how to format the SQL:
I am working with a very large stored procedure on our server that is not formatted well at all. I was thinking it would be great to create a new SQL File in my project, copy and paste the text from the stored procedure in there, and have the text editor apply auto formatting to all of the SQL.
When I call "Add > New Item" and get that dialog, there does not seem to be any Installed Template with the .sql extension.
I see the SQL Server Database template, but that is not what I need. The LINQ to SQL Classes is not right, either.
What template do I need to use to use the auto formatting built into the VS2010 interface?
Judging from your screenshot, you have a C# project (e.g. a library dll) open. This won't show an option to add a .sql file as those files are not normally associated with a C# kind of projects.
One way around it is:
In VS2010 main menu, go to File -> New -> File. In General tab, there's a SqlFile file type.
Add a file and save it to the disk in the location of your project.
Right-click on your project and select Add -> Existing Item. In the open file dialog, change the extension to *.* to show your .sql file.
Add file to the project. If needed, change "Build Action" and "Copy to Output Directory" properties to control how it behaves during the build.
What you are looking for shows up when you create a SQL Server Database project.
File > Add > New Project
Then when you add items you see options that should work:
*Note my screenshots are from VS2012 - but I think it is the same.
I hate Visual Studio's T-SQL designer, even with SQL Data Tools installed. I opt to open my project's .sql files in Management Studio.
Right-Click any .sql file in VS.
Navigate to "Open-with"
Choose "Add"
In the Program dialog type "explorer.exe"
Type whatever you want for the friendly Name, I use Management Studio
Click "OK"
Highlight the new record and choose "Set as default".
Now double clicking any .sql file in VS will open up whatever program opens when you double click a .sql file outside of VS. Using this method, I'm able to edit, add, and modify my sql files in management studio and save them back to the project seamlessly.
Hope this helps.
In my application I have created my own filetype, basically all it is is a normal text file with my own extension on it. Now my question is I want to be able to have my application open up these files on the users computer. So when the user clicks the file they saved from my application it will open up in only my application. I am going to be using clickonce to deploy my application, does it have this functionality in it already? My application is in vb.net.
You may have a look at How to: Create a File Association For a ClickOnce Application. Within the site there is a description how to set it manually. Within VS you may set it by following these steps:
open context menu of project (right click project in solution explorer)
go to Publish
Options
File Associations
There you can set all necessary assocs. You should also check out ClickOnce File Association on SO! (Note: access fileName to open by AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData)
You can find the answer here, is about creating file associations for a click once application.
Try this.
Hope it has everything you want.
Visit http://www.c-sharpcorner.com/UploadFile/scottlysle/CustomFileType12082006000848AM/CustomFileType.aspx
your Question consists of tow parts (I guess)
the first is how to create file association and the second is how to open the file when the app runs
to answer the first one
file association VB.NET
and the second one when you open the file you saved with you're app:
If My.Application.CommandLineArgs < 0 Then
MessageBox.Show("No File dragged into the application's executable!")
Else
Messagebox.Show("File " & My.Application.CommandLineArgs(0) & " is ready to open!")
End If
you can use
My.Application.CommandLineArgs(0)
as file path
best wishes
I have an Access database application and I would like to know the proper way of decompiling and recompiling it.
To Decompile an Access database you'll need to create a shortcut with the following elements:
Path to the MS Access Executable (MSACESS.exe)
Path to the database you would like to decompile
The /decompile flag
All together, then, the shortcut would look something like the following:
"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" "C:\users\tim\documents\Mydatabase.mdb" /decompile
Obviously, the paths will be different on your system.
I'd recommend making a backup of your database before running this command.
If you have any startup code in your database you should hold down the shift key to bypass the startup code execution.
Once the database opens, you can compact and repair the database to ensure optimal performance.
After the compact and repair, you can recompile the VBA code by opening any module and using the Debug Compile [DatabaseName] command.
If this is something you want to do frequently, you can create an "Access Decompile" shortcut in your SendTo Menu. Once you have this shortcut in the SendTo Menu you'll be able to right-click on any Access database and select "Send To --> Access Decompile", which is much easier than having to create a shortcut to the specific database.
Follow these steps to customize the Send To menu with an Access Decompile shortcut
Create a shortcut to the Access executable.
Append the /decompile flag in the Target for the shortcut. The shortcut will look like this:
"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" /decompile
Open Windows Explorer and paste the following into the address bar:
%APPDATA%\Microsoft\Windows\SendTo
Copy the shortcut you created into the SendTo Folder.
The Access Decompile Shortcut will now be available for use.
To invoke the Access Decompile shortcut, right click on an Access Database in Windows Explorer and select "Send To --> Access Decompile". Be sure to hold the shift key down to bypass any startup code in the database.
#Tim Lentine's practical instructions are good, but he leaves out the actual steps required for a decompile to be worth doing:
backup your database.
compact your database.
using the shortcut created with Tim's instructions, open your database.
close that instance of Access.
open a new instance of Access and open the database you just decompiled, but BE SURE YOU BYPASS ALL STARTUP CODE (i.e., hold down the shift key). If you don't do that, then you might as well go back to step 3 and try again, since if the startup code runs, your code will recompile before you are ready to do so.
compact the decompiled database (and be sure you hold down the shift key so that it bypasses the startup code; see #5).
open the VBE and on the Debug menu, choose COMPILE [name of project].
on the file menu, save the project.
compact again.
Why are all these steps necessary?
Because you want to not just decompile the VBA, you want to make sure that all the data pages where the compiled p-code was stored are completely discarded before you recompile.
I also recommend:
in VBE options, turn off COMPILE ON DEMAND
in the VBE, add the COMPILE button to your toolbar.
compile often with that button on the toolbar, after every two or three lines of code.
Decompile is not something you should use all the time, but during heavy-duty coding, I might do a decompile a couple of times a day. And I generally decompile/recompile as the last step before releasing an app into production use.
Last of all, read Michael Kaplan's article on the subject to understand it better.
The accepted answer is great, but it's a little impractical to create a shortcut for every database.
You can save this as a powershell module.
#for use with MSAccess 2010
Function Decompile-AccessDB{
param ([string]$dbFileName)
[string]$argument = '"' + $dbFileName + '"' + "/Decompile"
Start-Process -FilePath 'C:\Program Files (x86)\Microsoft Office\Office14\MSACCESS.EXE' -ArgumentList $argument
}
Then call it like this:
Decompile-AccessDB -Path "C:\Path\to\some.accdb"
This allows you to quickly and easily decompile any db from the power shell command line.
Note that you still need to hold down the Shift key when you run this to bypass the application startup.
I wrote a VBS script to automate the process of decompiling. It's silly that Microsoft hasn't integrated this into Access, considering it is a necessity when developing VBA-heavy applications.
The script locates MSACCESS.exe and runs Access with the decompile flag on a database located in the parent directory of the script, whose name is given in the code.
Option Explicit
Dim MSAccPath
Dim RegKey
Dim WSHShell
Dim currentDirectory
' Get MSACCESS.exe directory
RegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\" _
& "CurrentVersion\App Paths\MSACCESS.EXE\Path"
Set WSHShell = WScript.CreateObject("WScript.Shell")
' Get parent directory
MSAccPath = WSHShell.RegRead(RegKey)
currentDirectory = WSHShell.CurrentDirectory
' Decompile
WSHShell.Run Chr(34) & MSAccPath & "MSACCESS.EXE" & Chr(34) & " " & Chr(34) & currentDirectory & "\..\testdb.accdb" & Chr(34) & " /decompile"
' Clear shell var
Set WSHShell = Nothing
Simply paste this text into a document with a .vbs extension and double-click it to run. Access will launch, decompile the compiled P-code ("packed" code), and automatically recompile the VBA source back into P-code.
The other answers here all seem a little complex to my taste.
To decompile an Access database:
Open the Run dialog from the start menu, or hit Win + R
Type in: MSACCESS.EXE /decompile (a proper installation should open up the Access application, you could also provide the full path to MSACCESS.EXE), and press OK.
Access now opens. Open up your DB in the Access window that just opened. That will decompile it.
Or simply you can create a shortcut on your Desktop (with the /Decompile Flag) and drag drop your Access application holding SHIFT to bypass any code