How to create a object of java class in excel vba - vbscript

i have a java class..i have registered in my system(it has shown the message as
registed successfully)..but when i try to create an object(the code is as below)
It is throwing error as module not found..do i have set the path.if yes how..
Dim conn
set conn = createObject("Main")
Main is the java class which is in C:\windows\java\trustlib
Please help me out..i am new to excel vba

See this description of CreateObject. Your code should look like this
Dim conn
Set conn = CreateObject("<server>.Main")
Where <server> is the name of the application providing the object.

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")

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

how to generate a xml file for my VB project?

We are created a application using VB.So,Whenever i click the project exe file i want to create a xml file and store some config.details for my application for further needs.
Now i created that xml file in my local drive(d:\appConfig\config.xml).But we have to handover only our project exe to client.So,Client may have the D drive or not.So, How do i create the config xml file in common to all client machine.
This is my code:
Dim doc As XmlDocument = New XmlDocument
doc.Load("D:\appConfig\trial.xml")
Dim newElem As XmlElement
newElem = doc.CreateNode(XmlNodeType.Element, "file", "testing")
newElem.SetAttribute("filename", filenameenc)
newElem.SetAttribute("expdate", g)
Dim root As XmlElement = doc.DocumentElement
root.AppendChild(newElem)
doc.Save("D:\appConfig\trial.xml")
Is there any way to create the config xml?
Please guide me to get out of this issue?

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"

Getting "Object is read only" error when setting ClientCredentials in WCF

I have a proxy object generated by Visual Studio (client side) named ServerClient. I am attempting to set ClientCredentials.UserName.UserName/Password before opening up a new connection using this code:
InstanceContext context = new InstanceContext(this);
m_client = new ServerClient(context);
m_client.ClientCredentials.UserName.UserName = "Sample";
As soon as the code hits the UserName line it fails with an "Object is read-only" error. I know this can happen if the connection is already open or faulted, but at this point I haven't called context.Open() yet.
I have configured the Bindings (which uses netTcpBinding) to use Message as it's security mode, and MessageClientCredentialType is set to UserName.
Any ideas?
I noticed that after creating an instance of the proxy class for the service, I can set the Username and Password once without errors and do a successful call to my webservice. When I then try to set the Username and Password again on the existing instance (unnecessary of course) I get the 'Object is Read-Only' error you mentioned. Setting the values once per instance lifetime worked for me.
It appears that you can only access these properties pretty early in the instanciation cycle. If I override the constructor in the proxy class (ServerClient), I'm able to set these properties:
base.ClientCredentials.UserName.UserName = "Sample";
I'm beginning to appreciate the people who suggest not using the automatically built proxies provided by VS.
here is the solution:
using SysSvcmod = System.ServiceModel.Description;
SysSvcmod.ClientCredentials clientCredentials = new SysSvcmod.ClientCredentials();
clientCredentials.UserName.UserName = "user_name";
clientCredentials.UserName.Password = "pass_word";
m_client.ChannelFactory.Endpoint.Behaviors.RemoveAt(1);
m_client.ChannelFactory.Endpoint.Behaviors.Add(clientCredentials);
I have similar code that's passing UserName fine:
FooServiceClient client = new FooServiceClient("BasicHttpBinding_IFooService");
client.ClientCredentials.UserName.UserName = "user";
client.ClientCredentials.UserName.Password = "password";
Try creating the proxy with binding name in app.config.
The correct syntax is:
// Remove the ClientCredentials behavior.
client.ChannelFactory.Endpoint.Behaviors.Remove<ClientCredentials>();
// Add a custom client credentials instance to the behaviors collection.
client.ChannelFactory.Endpoint.Behaviors.Add(new MyClientCredentials());
http://msdn.microsoft.com/en-us/library/ms730868.aspx
It worked for me.
I was facing same problem, my code started working when I changed my code i.e. assigning values to Client credential immediately after initializing Client object.
here is the solution ,
ProductClient Manager = new ProductClient();
Manager.ClientCredentials.UserName.UserName = txtUserName.Text;
Manager.ClientCredentials.UserName.Password = txtPassword.Text;
This will not happen if the service reference is added through -> Add service reference ->Advanced->Add Web Reference-> Url/wsdl (local disk file).
I was facing this issue where I was trying to create a generic method to create a clients for different end points.
Here how I achieved this.
public static T CreateClient<T>(string url) where T : class
{
EndpointAddress endPoint = new EndpointAddress(url);
CustomBinding binding = CreateCustomBinding();
T client = (T)Activator.CreateInstance(typeof(T), new object[] { binding, endPoint });
SetClientCredentials(client);
return client;
}
public static void SetClientCredentials(dynamic obj)
{
obj.ChannelFactory.Endpoint.Behaviors.Remove<ClientCredentials>();
obj.ChannelFactory.Endpoint.Behaviors.Add(new CustomCredentials());
obj.ClientCredentials.UserName.UserName = "UserId";
obj.ClientCredentials.UserName.Password = "Password";
}
I think your problem might be related to the use of the InstanceContext. I thought that was only needed for duplex communication channels from the server side.
I admit I'm not sure about this, but I think in this case you are telling the client to use an existing instance context so it thinks there is already a running service and will not allow changes.
What is driving the use of InstanceContext?
If using a duplex client, when you instantiate it the DuplexChannelFactory within the DuplexClientBase that your client is derived from is initialized with existing credentials so it can open the callback channel, which is why the credentials would be read only.
I second Mike's question and also ask why are you using NetTcpBinding if you are not going to use its inherent transport level security? Perhaps an HTTP based binding would be a better fit? That would allow you to use certificate based security which I believe can be modified after instantiation (http://msdn.microsoft.com/en-us/library/ms576164.aspx).
A shot in the dark but does netTcpBinding allow username and password validation? Try using application layer (SOAP) security using a http binding
or you could just simply check the Credentials
if (client.ClientCredentials.ClientCertificate.Certificate == null || string.IsNullOrEmpty(client.ClientCredentials.ClientCertificate.Certificate.Thumbprint))
{
client.ClientCredentials.ClientCertificate.SetCertificate(
StoreLocation.LocalMachine,
StoreName.My,
X509FindType.FindByThumbprint, ConfigurationManager.AppSettings.Get("CertificateThumbprint"));
}
In .NET 4.6 I couldn't remove the credentials using Fabienne's answer. Kept getting Compiler Error CS0308 in the Remove method. What worked for me was this:
Type endpointBehaviorType = serviceClient.ClientCredentials.GetType();
serviceClient.Endpoint.EndpointBehaviors.Remove(endpointBehaviorType);
ClientCredentials clientCredentials = new ClientCredentials();
clientCredentials.UserName.UserName = userName;
clientCredentials.UserName.Password = password;
serviceClient.Endpoint.EndpointBehaviors.Add(clientCredentials);

Resources