Connection string in Visual Studio for Database Access - visual-studio-2010

My Access database is password: (password is '123')
What is the connection code in C#?
SqlConnection cnn = new SqlConnection();
cnn.ConnectionString = #"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=G:\My Project\DB.accdb;user=Admin;pwd=123";
cnn.open();
'ERROR Connection'

The correct connection string for Microsoft Access is something like this
#"Provider=Microsoft.ACE.OLEDB.12.0;
Data Source=G:\My Project\DB.accdb;
Jet OLEDB:Database Password=123;"
Of course you should use the appropriate provider. SqlConnection and the other classes from the namespace System.Data.SqlClient are used for Sql Server. Microsoft Access should uses the classes from the namespace System.Data.OleDb like OleDbConnection, OleDbCommand, OleDbDataReader etc...

This might help you out
Private connString = #"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=G:\My Project\DB.accdb;Jet OLEDB:Database Password=123;"
SqlConnection cnn = new SqlConnection(connString);
cnn.open();
//Do your Work
If you are using Microsoft Access accdb ODBC Driver
Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=G:\mydatabase.accdb;Uid=Admin;Pwd=123;

Related

Connecting VBA with oracle 11g enterprise edition

I am trying to connect VBA to Oracle 11 g- I was checking whether the connection string was fine.
While trying below code I am getting error while opening the connection.
Runtime error-3706 Application defined or object -defined error.
Can anyone help?
Code:
Sub getdatafromOracle()
Dim connectdb As ADODB.Connection
connectdb.ConnectionString = "PROVIDER= OraOLEDB.Oracle;DATA SOURCE=DBname;USER ID=uname;PASSWORD=Pword"
connectdb.Open
connectdb.Close
End Sub
You habe to initialize the Connection object before you can use it.
set connectdb = New ADODB.Connection
Maybe you have to use this syntax (I am not sure):
connectdb.Open("PROVIDER=OraOLEDB.Oracle;DATA SOURCE=DBname", "uname", "Pword")

Sql developer custom connection string

How to use custom connection string in Oracle sql developer to connect?
jdbc:oracle:thin:#(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)
(HOST=147.22.109.218)(port=1521))(ADDRESS=(PROTOCOL=TCP)
(HOST=147.22.109.219)(port=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=147.22.109.220)(port=1521)))
(FAILOVER=on)(LOAD_BALANCE=on)
(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=cmphpd)))
Please help. Thanks
To us a TNS connection string, in the New / Select Database Connection window where you configure the connection:
Set Connection Type to TNS
Under the Details tab select Connect Identifier
Put the connection string into the text box next to Connect Identifier
Click Test if you'd like, to make sure it works
Click Save
Similarly, under Connection Type there also seems to be an option for a custom JDBC URL if that's what you prefer.
(Instructions and screenshot from version 19.4, in case it makes a difference)
Try this:
jdbc:oracle:thin:#147.22.109.220:1521/cmphpd
These are the best and complete instructions I've found.
https://blogs.oracle.com/dev2dev/ssl-connection-to-oracle-db-using-jdbc,-tlsv12,-jks-or-oracle-wallets
Below are the steps which I took to fix this issue:
Install JCE (following the instructions in Readme) - JCE
Add below lines in build.gradle
System.setProperty('oracle.net.ssl_version', '1.2')
System.setProperty('oracle.net.ssl_cipher_suites', '(TLS_RSA_WITH_AES_256_CBC_SHA256)')
System.setProperty('oracle.net.tns_admin', './lib')
System.setProperty('oracle.net.ssl_server_dn_match', 'true')
Setup db connection like
String connString = "jdbc:oracle:thin:#(description=(address_list=
(address=(protocol=tcp)(port=1521)(host=prodHost)))
(connect_data=(INSTANCE_NAME=ORCL)))";
OracleDataSource ods = new OracleDataSource();
ods.setURL(connString);
ods.setUser("scott");
ods.setPassword("tiger");
Connection conn = ods.getConnection();

Database access issue with Visual Studio application

I has been created a program that works with MS Access 2010 (.accdb)extension. The program is fully works fine.
The issue is:
When the program is installed into another PC that has no MS Office installed, then the Exception that defined in the program returns connection error. Yes of course because the program can't read the (.accdb) file without office installed.
Need solution:
Is there any way to import this (.accdb) in order to read and modify it. Or is there any other simple solution that works when the application is installed to any non office installed PC?
The Demo of My program Code is:
Connection String:
Imports SpeechLib
Imports System.IO
Module MdlIPray5ve
Public con As OleDb.OleDbConnection
Public cmd As OleDb.OleDbCommand
Public sql As String
Public speaker As New SpVoice
Public Function connection() As String
Try
connection = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=azan_time.accdb; Persist Security Info=False;"
Catch ex As Exception
MessageBox.Show("Could not connect to the Database. Check your Connection!")
End Try
End Function
Something that Accesses the Database:
Private Sub UpdateAlarmTone()
Try
Dim cmdText = "UPDATE alarm_tone SET subhi= #subhi1, zuhur =#zuhur1, aser = #aser1, megrib = #megrib1, isha = #isha1"
Using con As New OleDb.OleDbConnection(connection)
Using cmd As New OleDb.OleDbCommand(cmdText, con)
con.Open()
cmd.Parameters.AddWithValue("#subhi1", txtSubhi.Text)
cmd.Parameters.AddWithValue("#zuhur1", txtZuhur.Text)
cmd.Parameters.AddWithValue("#aser1", txtAser.Text)
cmd.Parameters.AddWithValue("#megrib1", txtMegrib.Text)
cmd.Parameters.AddWithValue("#isha1", txtIsha.Text)
Dim infor As String
infor = cmd.ExecuteNonQuery
If (infor > 0) Then
MsgBox("Alarm Tone record updated successfuly")
Else
MsgBox("Update failed!")
End If
End Using
End Using
Catch ex As Exception
MessageBox.Show("There is a problem with your connection!")
End Try
End Sub
create the Access database via ODBC, that comes with Windows itself.
You can also use other databases (eg., MySQL, Firebird, SQLite, and others) that are available that wouldn't necessarily cost your client anything if they installed it (or, for some, if you included it in your installation for them).
Using the MS Office COM automation requires that the MS Office product be installed on the machine running the automation.
There are third-party code libraries that replace that functionality with their own code, meaning your app could create it's own Access-compatible files. However, your users would still need Access to use them

RavenDB domain error

I have set up an instance of RavenDB on IIS. I can connect to it just fine using a network service application, however when I try and connect then initialize using an application running under local administrator I get an error "Unable to determine the identity of domain". The only thing I can think of is trying to impersonate "Network Service", but I am not sure if that is possible. The administrator has full rights to raven web folder.
Figured out this problem. I had to run my Raven document store connect and initialize in a different application domain. I ended up doing this.
string pathToDLL = installerFolder + "\\RavenSiteSetup.dll";
AppDomainSetup domainSetup = new AppDomainSetup {
ApplicationBase = installerFolder,
PrivateBinPath = pathToDLL
};
Evidence ev1 = new Evidence();
ev1.AddAssemblyEvidence(new ApplicationDirectory(
typeof(RavenSetup).Assembly.FullName)
);
ev1.AddHostEvidence(new Zone(SecurityZone.Internet));
AppDomain ad = AppDomain.CreateDomain("RavenSetup", ev1, domainSetup,
Assembly.GetExecutingAssembly().PermissionSet,null);
IIdentity identity = new GenericIdentity("RavenSetup");
IPrincipal principal = new GenericPrincipal(identity, null);
ad.SetThreadPrincipal(principal);
RavenSetup remoteWorker = (RavenSetup)ad.CreateInstanceFromAndUnwrap(
pathToDLL,
typeof(RavenSetup).FullName);
remoteWorker.Connect(sitePath);
Connecting locally, are you using http://localhost:[port]? I've had problems using the domain name locally.
Try running your application locally and connect to the RavenDB via locahost address.

ORA-01019 connecting to Oracle from Excel

I have installed Oracle 10g Express Edition. When try to test the connection I am getting the error "Error while trying to retrieve text for error ORA-01019".
Below is my code.
strConnection = "Driver={Microsoft ODBC for
Oracle};Server=Servername;Uid=username;Pwd=password;"
Set conn = CreateObject("ADODB.Connection")
conn.Open strConnection
conn.Close
Set conn = Nothing
Thanks in advance
I had the following error occur recently.
System.Runtime.InteropServices.COMException (0x80004005): ORA-01019: unable to allocate memory in the user side
at ADODB.ConnectionClass.Open(String ConnectionString, String UserID, String Password, Int32 Options)
I managed to resolve the problem by simply modifying my connection string.
from:
"Provider=MSDAORA.1;Data Source=tprss;Persist Security Info=True;User ID=myUser;Password=myPassword"
To:
"Provider=MSDASQL;Data Source=tprss;Persist Security Info=True;User ID=myUser;Password=myPassword"
someone modified/updated the components on the box.
"ORA-01019 unable to allocate memory in the user side
Cause: The user side memory allocator returned an error.
Action: Increase the size of the process heap or switch to the old set of calls."
Followup from the comments:
Could you try this code?
Dim Cn As ADODB.Connection
Dim CP As ADODB.Command
Dim Rs As ADODB.Recordset
Dim Conn As String
Dim QSQL As String
'Connect to Oracele server begin
Conn = "DRIVER={ORACLE ODBC DRIVER};SERVER=Service name;UID=username;PWD=password;DBQ=Service name;DBA=W;APA=T;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;FRL=F;MTS=F;CSR=F;PFC=10;TLO=O;"
Set Cn = New ADODB.Connection
With Cn
.ConnectionString = Conn
.CursorLocation = adUseClient
.Open
End With
If Cn.State = adStateOpen Then
MsgBox "Connection successful."
End If
'Connect to Oracle server end
'close connection begin
Cn.Close
Set Cn = Nothing
Set CP = Nothing
'close connection end
(This didnt fit in a Comment box)
You need at least one driver. The oracle driver is best but Microsoft Driver will work too.
Lets first try to make a connection string. Right click on your desktop and the create a new .txt file.
Now rename your textfile to something.udl
Double click on the udl file. Go to "Provider" and select Microsoft OLEDB Provider for Oracle. Then click on next. In the server name field you fill in your TNS name. Then username and password and put a V inside "Allow saving password" (we will need this) And click on test connection. Make sure this works.
If it works then click on OK. Now open the UDL file with a text editor. You will see something similar to:
[oledb]
; Everything after this line is an OLE DB initstring
Provider=MSDAORA.1;Password=yourpw;User ID=youruser;Data Source=yourTNS;Persist Security Info=True
Copy this part into your connection string:
Provider=MSDAORA.1;Password=yourpw;User ID=youruser;Data Source=yourTNS
Now your connection string should look like:
Conn = "Provider=MSDAORA.1;Password=yourpw;User ID=youruser;Data Source=yourTNS"
I hope this works.
We had the same problem, specifically on Windows 7 when using the Microsoft OleDb driver from VB6.
Following the instructions in this post fixed out problem:
http://prasanth4microsoft.blogspot.com/2010/11/windows7-excel-vba-ora-01019-unable-to.html
I had this problem also but it is on win10.. After I have tried a lots of different solution from web .. Finally.. it worked to change connection string to fix this problem.. But I changed "Provider=MSDAORA.1" to "Provider=OraOLEDB.Oracle"

Resources