I'm trying to make a connection with a dbf file trough Visual Basic, i'm using the following connection string:
dbConn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source="C:\Users\joelgjunior\Desktop\PROVISAOMAT_012020.dbf";Persist Security Info=False;
The connection string seems correct, but the code can't recognize the dbf file i don't know why, the name and the path are written correctly but the vb always say that is not a valid path, otherwise i did it to an accdb file and it worked. Can someone help me in this case? Thanks
A connection string points to the PATH where the data files are located. Then, any .dbf within that path location (or child-folder within) is accessible.
Think of it this way. A normal SQL command might be
select * from PROVISAOMAT_012020 where...
The SQLCommand object uses the CONNECTION to point to the location. So if the connection has the dbf name as well, your query will basically be interpreted as
select * from C:\Users\joelgjunior\Desktop\PROVISAOMAT_012020.dbf\PROVISAOMAT_012020 where...
Also, if using .DBF files, is it dBASE, or Visual FoxPro (VFP), if VFP, I would download those drivers and use them instead of ACE.
Related
I'm using this ForEach loop tutorial in an attempt to import all my Excel files from a folder to an SQL table via SSIS. I followed the steps exactly but can't get the Excel source block to recognize the variable filename. The error I get shows that the filepath did not work at all:
Could not retrieve the table information for the connection manager ConnectionManagerName
The source file formatting, type, and folder are consistent. Has anyone else had this problem? I suspect I'm missing something between steps 2-4 in the link, but I wouldn't know what it is.
I've solved it! I used a ConnectionString in Step 3b instead of ExcelFileName. For anyone reading this answer, the exact ConnectionString format will vary (see here) but will be something like
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\myFolder\myExcel2007file.xlsx;
Extended Properties="Excel 12.0 Xml;HDR=YES";
I made a desktop application in vb.net. I give the reference path of connection string through the .udl. The problem is when I place the folder in another location the path string does not change and hence results in an error. Kindly suggest. Connection details are as follows
_connStr = System.IO.File.ReadAllText("C:\Users\avt\Desktop\New folder\a.udl")
con = New OleDbConnection(_connStr)
First of all, why are you using Text file to save your connection String ?
Go to Project Properties -> Settings and create a ConnectionString setting to save your connection string. That'll solve your problem. Using a Text file for ConnectionString is not a valid way.
I am developing a Windows application in Visual Studio 2008 with SQL Server CE as database. D:/My Project/Library is the root directory for my project's source code.
I have some files which I want to access within the forms of my project. They are stored in D:/My Project/Library/New Resources. To access those files I can't use the full path name because I keep changing the location of my project's source code. I need something like wherever the source directory may be the files must be accessed from there only.
Ex:
Public Sub setconnection()
con = New SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=H:\Library\Library\Library1.mdf;Integrated Security=True;User Instance=True")
cmd.Connection = con
con.Open()
End Sub
I want to use relative path name for Library1.mdf file without using H:\Library\Library path name.
This has worked for me, though you may need to tack on some additional info. A web project using this, for example, may need to append "/bin" to the end of the result to get the actual location of the DLLs.
AppDomain.CurrentDomain.BaseDirectory
I am attempting to insert new records into an access 2010 database that is located on a network drive with a windows form app developed in Visual Studio 2010 using vb.net. When using the mapped drive letter in the path the connection string works properly, but when using the UNC path I receive an error telling me that it "is not a valid path".
The working path looks like this...
Dim dbSource = "Data Source= L:\server\directory\file.accdb"
The path that errors looks like this...
Dim dbSource = "Data Source= \\server\directory\file.accdb"
Is there something basic I'm missing? The only difference is the use of the UNC path.
As a secondary question, would there be any issue to just use the mapped drive letter if I anticipate all users would have the server mapped to the same drive letter?
My Visual Basic project uses this connecton string:
Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Admin\Desktop\IzolacCold V2\IzolacCold V2\izolac_cold_dbv2.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True
When I debug it, and go to debug folder, or when I "Release" it then problem occurs. If I run exe file program works normally but it save's data in database defined in connection string and not in database that is created in DEBUG folder (or RELESE folder).
How to properly connect to my databes. How to build proper connection string ?
You should use the DataDirectory substitution string.
For example you could write your connectionstring as
Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\izolac_cold_dbv2.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True
In your code then you could control the exact location of the DataDirectory executing this code, BEFORE any attempt to open a connection.
Dim commonDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)
Dim myAppDataFolder = Path.Combine(commonDataFolder, "MyAppName")
if Not Directory.Exists(myAppDataFolder) Directory.CreateDirectory(myAppDataFolder)
AppDomain.CurrentDomain.SetData("DataDirectory", myAppDataFolder)
(This example use the C:\programdata\myAppName folder because it is the most appropriate location for read/write data files needed by your application
Your deployment procedure should take care to create the above folder and place the database file in this location.