Connect MS Access Database (.mdb) using ip address with VB.NET Application - vb.net

I am connecting my VB.NET windows application to server. I am using this code:
Dim con As New OleDb.OleDbConnection
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\162.222.225.78\httpdocs\CM.mdb;"
con.Open()
MsgBox("Database is now open")
con.Close()
MsgBox("Database is now Closed")
But I am getting error:
'\162.222.225.78\httpdocs\version.txt' is not a valid path. Make sure
that the path name is spelled correctly and that you are connected to
the server on which the file resides.
Please help.

this is the issue for mdw file which is your OLEDB is not finding.
search the .mdw file and copy it in that folder where your mdb file is present.
if it not works do the below..
add Properties("Jet OLEDB:Database Password") = "password" to your connection string
like this..
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=162.222.225.78/CRM.mdb;User=corpopef;Password=**;Properties("Jet OLEDB:Database Password") = "password(try the admin password here)""
if it also not works
write the connection string as "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=162.222.225.78/CRM.mdb;persist security info=false"
have you tried to find connection from the container's(from tool box) properties on page??

Please do two things..
1- take a container control(like datagrid) on your page choose datasource from gridview task,
it will connect to your database where ever it is then copy that connection string from there.
definitly it will work.
2-if it does'nt work plz restart your system as the MS access databse shows this type of problems.

Related

I need to have a connection string that changes for new devices

So I'm using this post as a last resort, newcomer here, my connection string currently looks like this for my local MSSQL database:
Dim Conn As New SqlConnection("Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\steve\OneDrive\Desktop\UNIT 5 CS\MonmouthCanoeAndActivityCentre\MonmouthCanoeAndActivityCentre\.vs\MonmouthCanoeAndActivityCentre\.vs\MonmouthCanoeAndActivityCentre\v16\WorkerLogin.mdf;Integrated Security=True;Connect Timeout=30")
which is of course incredibly clunky and also hard coded to my personal laptop. My problem is that I want to be able to run the connection on any new device I send the project to without them having to change the directory of the connection string themselves.
Any advice would be helpful, I'm not incredible at visual basic either so sorry if I question.
Answering my own question to hopefully help some poor future soul.
the new connection string is:
Dim conn As New SqlConnection("Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" & Application.StartupPath & "InsertFileNameHere.mdf;Integrated Security=True;Connect Timeout=30")
The .mdf file of your database has to be in the same place as your Application.StartupPath but you can find this with a simple:
Dim location As String = Application.StartupPath
MessageBox.Show(location)
and a test button to activate the above ^

Set password for SQLite v3 database

My application uses a database stored in a file available via network. So far, I've been using a MS-Access file (.accdb), but I'm trying to migrate to SQLite Version 3 (.db3).
I added SQLite NuGet package to my project and created a SQLite database using SQLiteStudio. I refactored my database objects to work with System.Data.SQLite.SQLiteConnection instead of System.Data.OleDb.OleDbConnection and it worked well.
However, my previous accdb database was password protected, and I don't know how to apply a password over my current SQLite database.
Can anyone teach me ho to do it? Thanks in advance!
I followed the link which Wudge kindly appointed in comment above, and it works, but I'd rather clarify what need to be done:
To set a password to an unprotected database:
Dim conn = New SQLite.SQLiteConnection(
"Data Source=C:\yourFolder\yourDB.db3;Version=3;")
conn.Open()
conn.ChangePassword("password")
conn.Close()
To open a password-protected database:
Dim conn = New SQLite.SQLiteConnection(
"Data Source=C:\yourFolder\yourDB.db3;Version=3;")
conn.SetPassword("password")
conn.Open()
conn.Close()
or
Dim conn = New SQLite.SQLiteConnection(
"Data Source=C:\yourFolder\yourDB.db3;Version=3;Password=password;")
conn.Open()
conn.Close()
To remove password from a password-protected database:
Dim conn = New SQLite.SQLiteConnection(
"Data Source=C:\yourFolder\yourDB.db3;Version=3;Password=password;")
conn.Open()
conn.ChangePassword(String.Empty)
conn.Close()
PS. The open source database manager SQLiteStudio is able to open files which were password-protected that way, as long as you choose System.Data.SQLite instead of Sqlite 3 as your database type. (Requires v 3.1.1, the current version).

An unhandled exception for MS Access connection

I am trying to connect to a server in a Windows application in VB.NET. I am using this code
Dim con As New OleDb.OleDbConnection
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=//corpopef#162.222.225.78/CRM.mdb;database=User=corpopef;Password=****;"
con.Open()
MsgBox("Database is now open")
con.Close()
' ftpes://corpopef#162.222.225.78/CM.mdb
MsgBox("Database is now Closed")
but i am getting an error saying
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
Additional information: Cannot start your application. The workgroup information file is missing or opened exclusively by another user.
plz help..
As mentioned in the comments, you should go look at http://www.connectionstrings.com/access/
If you do go and look at that site, you'll see that the connection string for an access database with password should be
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccessFile.accdb;
Jet OLEDB:Database Password=MyDbPassword;
Whereas what you have is
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=//corpopef#162.222.225.78/CRM.mdb;database=User=corpopef;Password=****;
Now, I honestly can't remember if the slashes make a difference (it's been a long time since I've tried connecting to anything like this), but lets assume they do, in which case, the first bit of your connection string is almost correct, reversing the slashes will give you:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\corpopef#162.222.225.78\CRM.mdb;
You then need to declare the database password, which gives you:
Jet OLEDB:Database Password=*******;
(obviously, unless the database password is 7 *'s, put the password in there)
So your completed connection string would be:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\corpopef#162.222.225.78\CRM.mdb;Jet OLEDB:Database Password=*******;
Which means your code should be:
Dim con As New OleDb.OleDbConnection
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\corpopef#162.222.225.78\CRM.mdb;Jet OLEDB:Database Password=*******;"
con.Open()
MsgBox("Database is now open")
con.Close()
' ftpes://corpopef#162.222.225.78/CM.mdb
MsgBox("Database is now Closed")
You're likely to get more civil and also more helpful responses if you don't panic and beg for help and actually think about what people are saying in the comments. The main reason I'm helping is because 1) I've got a spare few moments, and 2) I know how upsetting it is when you're at the end of your tether, can't figure something out and just want it done.

Setting Up SqlConnection string in vb.net for a local database created through visual studio 2010

I have been searching for a couple hours, and found several questions, but none of them really explained this in a way I can understand.
I'm programming a game similar to Rock Paper Sissors, except with many more selections, and the possiblity of a tie. I had originally hardcoded all of the possible outcomes, then decided to try a database so I can learn and practice sql as well.
Problem is, I can't figure out for the life of me how to connect to my local database, now that I have set it up and filled it through Visual Studio 2010. I can connect to it through Server Explorer just fine, and I can see it in Solution Explorer. I've tried several things, along the lines of:
Private sqlConn As New SqlConnection("Data Source=(local)|DataDirectory|\Outcomes.sdf;database=Outcomes;Integrated Security=true")
Private sqlConn As New SqlConnection("Data Source=.\SQLEXPRESS; Integrated Security=true")
Dim sqlConn As SqlConnection
sqlConn = New SqlConnection("DataSource=..\..\Outcomes.sdf")
I am relatively new to sql, but know enough through tinkering to build a sql statement and get me the result I want. But I've never connected to a database before. I've looked on MSDN and tried several things I saw on there (everything that looked like what I needed, really) but it still hasn't worked.
If I can connect, I already have my statement set, and have tested it through the database itself. Any help would be wonderful, especially if it's explained in a way I can understand it and use it for later.
Also, if it helps and isn't noticed through my tried code, my db name is Outcomes. I don't know if that is needed or will help, but just in case.
Please visit connection strings here...
It also would have been helpful to know what type of DBMS you are using as well. I noticed you have an .sdf database file, not a DBMS (For ex: MySql, SQL or Oracle). Therefore, your connection string is really going to depend on what you want.
Your issue is here by the way...
Private sqlConn As New SqlConnection("Data Source=(local)|DataDirectory|\Outcomes.sdf;database=Outcomes;Integrated Security=true")
*You cant use the SqlConnection you have because its not supported with the use of .sdf files.
Instead you have to use: System.Data.SqlServerCe 'This is for compact edition
If you would like to know more about this please see here.
Kendra,
Here are the logical Steps you will need to follow to access the database programmatically:
Note: I'm assumming you have the proper SQLExpress | SQL Server Database setup whether local or remote the methods below are identical except for the connection string information.
1) Import the Sql AdoNet Namespace so you can use the proper SQL Server Client Objects & Methods;
a) Imports System.Data.SqlClient
2) Establish a Connection to the database with the ADO Connection Object:
' Create your ADO Connection Object:
Private myConn As SqlConnection
myConn = New SqlConnection("Initial Catalog=OutComes;" & _
"Data Source=localhost;Integrated Security=SSPI;")
Note: This connection string uses integrated security from your windows machine. you could also use standard security where you would need to enter your username and password credentials. Its your choice.
3) Setup Your ADO Command Object to Define your data retrieval query:
'Create a Command object.
Private myCmd As SqlCommand
myCmd = myConn.CreateCommand
myCmd.CommandText = "SELECT FirstName, LastName FROM Employees"
'Open the connection.
myConn.Open()
Note: Subsitute CommandText string for your actual query based upon your own database schema.
4) Read, Fetch, Display Data using the SQLDataReader Object:
Private results As String
Private myReader As SqlDataReader
myReader = myCmd.ExecuteReader()
'Traverse the DataSet and Display in GUi for Example:
Do While myReader.Read()
results = results & myReader.GetString(0) & vbTab & _
myReader.GetString(1) & vbLf
Loop
'Display results.
MsgBox(results)
5) Gracefully Close all Objects Used:
' Close the reader and the database connection.
myReader.Close()
myConn.Close()
Note - You'll need to consult microsoft for further connection string formats, since I don't have enough info. But this should clarify the actual big picture steps for you.
Regards,
Scott

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