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.
Related
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.
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
I'm using a SQL Server Compact database (3.5). I have run through every article on this site (and others) I could find about this issue, but can't seem to find the problem. I am using Visual Studio 2012, VB.Net.
My provider string is:
Dim sqlConn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.SQLServer.CE.OLEDB.3.5;Data Source=" & My.Application.Info.DirectoryPath & "\pw.sdf" & ";Password=XXXyyy1234;Persist Security Info=True;")
My code where it all breaks down is:
'Create SQL Query
Dim SQLString As String = "SELECT * FROM EmailGroups"
'Create Dataset, Open Connection
Dim dsPWC As New DataSet()
Dim OleDbDataAdapter1 As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter(SQLString, sqlConn)
sqlConn.Open()
And, of course, it breaks down on .Open().
I picked selecting from that datatable because it is a simple one.
EmailGroup_UID [int][PK]
EmailGroup_Name [nvarchar][length=50]
I'm sure I've been simply staring at this too long and can't see the forest for the trees anymore, so I'm hoping someone can slap me straight :)
Thanks in advance.
EDIT: This code all works when tying to the original MS Access 2007 database (accdb). Different provider, of course. And - I didn't import the tables, I re-created manually.
2nd EDIT: Immediate Window says 'A first chance exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll'
You should use SqlCeConnection instead of OldDbConnection.
if you must use OleDbConnection, use "ssce:database password" like so:
"Provider=Microsoft.SQLServer.CE.OLEDB.3.5;Data Source=" & My.Application.Info.DirectoryPath & "\pw.sdf" & ";SSCE:Database Password=XXXyyy1234;Persist Security Info=True;"
I've got a VB.NET console application I'm creating that will make it easier for people to work with some test databases, and part of this is having a function that restores the database. I thought it was fairly straightforward, and here is the code I have so far:
Sub Restore()
con = New SqlConnection("Data Source=" & utilnamespace.sqlSvr & ";Database=Master;integrated security=SSPI;")
cmd = New SqlCommand("ALTER DATABASE [db] SET OFFLINE WITH ROLLBACK IMMEDIATE RESTORE DATABASE db FROM DISK = 'G:\db.bak' WITH REPLACE, STATS = 10", con)
cmd.Connection.Open()
cmd.ExecuteNonQuery()
Console.WriteLine(cmd.CommandText)
cmd.Connection.Close()
End Sub
The SQL works fine if I run it in SSMS, however it will time out if I try to run it from the app. The problem is that I've read over this and I'm still unsure of what to do.
Should I use BeginExecuteNonQuery and then have it listen for the statement complete message somehow?
Even if I believe that showing a waiting form and waiting for some kind of confirmation would be better for the end user... have you tried changing the timeout in the connection string to solve it in a quick way?
eg (seconds):
string connStr = "Data Source=(local);Initial Catalog=db;
Integrated Security=SSPI;Connection Timeout=30";
Also check these links:
SQL Server Management Objects (SMO)
SQL Server 2008 - Backup and Restore Databases using SMO
If the database is too big you can increase the timeout of the Command, not the connection string
cmd.Connection.Open()
cmd.CommandTimeout = 100
cmd.ExecuteNonQuery()
Console.WriteLine(cmd.CommandText)
cmd.Connection.Close()
Hey all i am VERY new to a Oracle DB and i am trying to connect to it via VB.net 2010. I have been trying the following:
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim dr As OleDbDataReader
myConnection = New OleDbConnection("Provider=MSDAORA.1;UserID=xxxx;password=xxxx; database=xxxx")
'MSDORA is the provider when working with Oracle
Try
myConnection.Open()
'opening the connection
myCommand = New OleDbCommand("Select * from emp", myConnection)
'executing the command and assigning it to connection
dr = myCommand.ExecuteReader()
While dr.Read()
'reading from the datareader
MessageBox.Show("EmpNo" & dr(0))
MessageBox.Show("EName" & dr(1))
MessageBox.Show("Job" & dr(2))
MessageBox.Show("Mgr" & dr(3))
MessageBox.Show("HireDate" & dr(4))
'displaying data from the table
End While
dr.Close()
myConnection.Close()
Catch ee As Exception
End Try
And i get the error on the Catch ee As Exception line: ORA-12560: TNS:protocol adapter error
I also have a tnsnames.ora file on my computer but i am unsure if i need to use that when connecting (or really, how too in the first place)? Is it needed for the code above?
I am trying to use a DNS-Less connection to the DB. Not sure if that is what it is doing in this or not?
Any help would be great!!! :o)
David
There are many ways: the one I use almost every time that doesn't require an entry in TNSNAMES.ORA is this:
Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=MyOracleSID)));User Id=myUsername;Password=myPassword;
And if you don't need an OleDb connection I think you should use System.Data.OracleClient or any other free provider (like DevArt dotConnect for Oracle Express)
Source: http://www.connectionstrings.com/oracle
I always use www.connectionstrings.com/ when I need to create a new connection string to the DB and when connection string format is not on top of my head.