UNC File Path is not working as connection string for an access database located on a network drive - vb.net

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?

Related

DBF file is not a valid Path - VBA

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.

HOW to finalize my vb.net and work without error in MS access database destination

i have three paths/destinations in my vb.net project, i want to make it work in all computers i add my program in it.
my database destination was
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\sh\Desktop\TEST\Database.accdb
after i compiled and build the project, it works
BUT after i copy the program in another computer it doesnt work.
then i changed my destination to...
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Database.accdb"
also i tried
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=..\Database.accdb"
BUT THEY ARE NOT WORKING
my other destination for open my DGV in PDF "im using iTexSharp"
Dim fontArialBold As BaseFont = BaseFont.CreateFont("c:\windows\fonts\arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED)
Dim folderPath As String = "C:\Users\Sha\Desktop\"
also can the program work in a computer doesn't have VB.net or MS access?

How can I get access to the files root directory without giving full path name in VB .NET

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

Error while uploading Excel data to SQL server 2005

I have a requirement to upload excel data into a SQL Server 2005 table. Initially I copied Excel data to a temp table and based on condition I have updated and inserted records into the SQL Server table.
Everything works fine in my local system. Same program I moved to quality server there I faced this error
The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.
Then we installed 'Microsoft.ACE.OLEDB.12.0 provider on quality server. Now this error appearing
The Microsoft Office Access database engine cannot open or write to the file ''. It is already opened exclusively by another user, or you need permission to view and write its data."
Kindly help me out to solve this issue.
SqlConnection con = new SqlConnection();
con = SQLManager.openSQLConnection();
string path = FileUpload1.PostedFile.FileName;
string excelConnectionString = #"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0 Xml;Persist Security Info=False";
//Create Connection to Excel work book
OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
OleDbCommand cmd = new OleDbCommand("Select [CM_CODE],[CM_NAME],[CM_ADD1],[CM_ADD2],[CM_ADD3],[CM_ADD4],[CM_CITY],[CM_PHONE],[CM_CG_CODE],[CM_CO_CODE],[CM_EXPIRY_DATE],[CM_PINCODE],[CM_EMAIL] from [Sheet1$]", excelConnection);
excelConnection.Open();
OleDbDataReader dReader;
dReader = cmd.ExecuteReader();
Regards,
Sathya
This is most likely a file permissions issue. Does the account that the program runs under have folder level permission to read files from the file location.
Find out which account the program runs under and then add appropriate access permissions to the folder where you upload your excel files.
If it's IIS then whichever account your app pool runs under needs write access to the folder that you upload to. Permissions can usually only be set by web server admin.
Wing
Finally i found out the solution.
I have created one folder under my application folder in Quality server.
Uploaded excel sheets wil get stored under this new folder.
and that path i am referring while updating my SQL server database.
Everything works fine now...
Thank u all for your support
Regards,
Sathya

Connection String for a local database across multiple users

How do you use the connection string on a local database in a way that would allow you to transfer the project folder from one computer to another, without having to modify the connection string?
Not like this
connection_String As String = "Data Source=C:\Users\Kyle\Desktop\CSCI_388_Group_Project\CSCI_388_Group_Project\CSCI_388_Group_Project\CSCI_388_Group_Project_Database.sdf"
More like this
connection_String As String = "Data Source=|DataDirectory|\CSCI_388_Group_Project_Database.sdf"
If I try to enter the second example into the connection field under the database properties I get an illegal character error.
The Environment class contains most of the paths you'll need.
You can call Environment.GetFolderPath to get a special directory. For example, to get the My Documents directory, call Environment.GetFolderPath(Environment.SpecialFolder.Personal).
You can browse all of the special folders here:
http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx
In your example specifically, you'd use the following:
connection_String As String = _
"Data Source=" &
Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
"CSCI_388_Group_Project_Database.sdf" )
Alternative:
Is it possible to just ask the user? If it's on their desktop, they might move it.
If you decide to keep the sdf file in the same folder in which your exe would reside, then you can do like this.
Dim ExeFolder As String = AppDomain.CurrentDomain.BaseDirectory
Dim connection_String As String = "Data Source=" & ExeFolder & "CSCI_388_Group_Project_Database.sdf"
Hope it helps !
One simple way is to use an environment variable to specify your path to the folder.
Then in your VB program using the Environ function to get the environment variable settings and use string manipulation to build your connect string.
You will need to have a default in case the environment variable is not set.
However when you launch your application, you can do it within a script that will set the environment variable.
A second method is to specify the path name on the application command line so that when the application is launched, it will specify the path using the command line.
A third method is to have a Windows registry key that you use. Then, similar to the environment variable, you query the Windows Registry for the folder path, then build your connect string from that.
With this third method you can have your application installer insert the Registry key.
A fourth method is to have an .ini file that contains an entry for the folder path.