I need to copy some documents from one container to another container in XML DB 2.5.16.
Below is the snippet to open those containers
public static void main(String[] args) throws DatabaseException {
EnvironmentConfig config_1 = getEnvConfig();
EnvironmentConfig config_2 = getEnvConfig();
Environment dbEnv_1 = new Environment(<dbEnvPath1>, config);
Environment dbEnv_2 = new Environment(<dbEnvPath2>, config_new);
XmlManager mgr_1 = new XmlManager(dbEnv_1 ,getManagerConfig());
XmlContainer cont_1 = mgr_1.openContainer(<containerName_1>, getContainerConfig());
XmlManager mgr_2 = new XmlManager(dbEnv_2,getManagerConfig());
XmlContainer cont_2 = mgr_2_new.openContainer(<containerName_2>, getContainerConfig());
}
private static EnvironmentConfig getEnvConfig() throws
DatabaseException{
EnvironmentConfig config = new EnvironmentConfig();
config.setErrorStream(System.err);
config.setAllowCreate(true);
config.setRunRecovery(true);
config.setTransactional(true);
config.setInitializeLocking(true);
config.setInitializeLogging(true);
config.setInitializeCache(true);
config.setLogAutoRemove(true);
config.setCacheSize(134217728);
config.setMaxLocks(80000);
config.setMaxLockers(4000000);
config.setMaxLockObjects(80000);
config.setMaxMutexes(86068);
config.setMaxMutexes(70000);
return config;
}
private static XmlManagerConfig getManagerConfig(){
XmlManagerConfig mconfig = new XmlManagerConfig();
mconfig.setAllowExternalAccess(true);
return mconfig;
}
private static XmlContainerConfig getContainerConfig(){
XmlContainerConfig cconfig = new XmlContainerConfig();
cconfig.setAllowValidation(false);
cconfig.setTransactional(true);
return cconfig;
}
While running this code, I got following error
PANIC: fatal region error detected; run recovery
com.sleepycat.dbxml.XmlException: Error: DB_RUNRECOVERY: Fatal error, run
database recovery, errcode = DATABASE_ERROR at com.sleepycat.dbxml.dbxml_javaJNI.XmlManager_openContainerInternal__SWIG_0(Native
Method)
at com.sleepycat.dbxml.XmlManager.openContainerInternal(XmlManager.java:621)
at com.sleepycat.dbxml.XmlManager.openContainer(XmlManager.java:197)
Try running fatal recovery, as described in the documentation here:
https://docs.oracle.com/cd/E17276_01/html/gsg_xml_txn/java/recovery.html
// Run catastrophic normal recovery
config.setRunFatalRecovery(true);
Related
I want to create 2 containers but the agent of my second container shows a problem
ERROR: Agent robot10 died without being properly terminated !!!
when i delete the second container it works
Runtime Instance = Runtime.instance(); Instance.setCloseVM(true);
ProfileImpl Profile = new ProfileImpl(true);
Profile.setParameter(Profile.CONTAINER_NAME, "Pacman");
Profile.setParameter(Profile.MAIN_HOST, "localhost");
AgentContainer Conteneur = Instance.createAgentContainer(Profile);
for (int i = 1; i <= n; i++) {
AgentController Agent = Conteneur.createNewAgent("robot" + String.valueOf(i), "package1.robot", Parametres1);
Agent.start();
}
AgentContainer Conteneur1 = Instance.createAgentContainer(Profile);
AgentController Agent = Conteneur1.createNewAgent("robot10" , "package1.robot", new Object[] {});
Agent.start();
It is still showing errors
Here is the code
package package1;
import jade.Boot;
import jade.core.AID;
import jade.core.Agent;
import jade.core.Profile;
import static jade.core.Profile.PLATFORM_ID;
import jade.core.ProfileImpl;
import jade.domain.DFService;
import jade.domain.FIPAAgentManagement.DFAgentDescription;
import jade.domain.FIPAException;
import jade.lang.acl.ACLMessage;
import jade.wrapper.AgentContainer;
import jade.wrapper.AgentController;
import jade.wrapper.ContainerController;
import jade.wrapper.StaleProxyException;
import javax.swing.UIManager;
public class launch extends Agent {
static DFAgentDescription agentDescription;private static AID aid;
static ACLMessage message1, message2;
launch() throws FIPAException{
agentDescription = new DFAgentDescription();
agentDescription.setName(getAID());
DFService.register(this, agentDescription);
DFService.register(this, agentDescription);
}
public static void main(String[] args) throws StaleProxyException {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (Exception e) {
}
try {
String[] arg = { "-gui","ClusteringAgent:multi.agent_clustering.ClusteringAgent" };
Boot.main(arg);
} catch (Exception e) {
e.printStackTrace();
}
jade.core.Runtime rt = jade.core.Runtime.instance(); rt.setCloseVM(true);
String containerName="Mycontainer1";
ProfileImpl pContainer = new ProfileImpl(true);
pContainer.setParameter(Profile.CONTAINER_NAME,containerName);
System.out.println("Launching container "+pContainer);
ContainerController containerRef = rt.createAgentContainer(pContainer);
AgentController Agent = containerRef.createNewAgent("robot" + String.valueOf(1), "package1.launch", new Object[] { 2});
Agent.start();
//create container2
containerName="Mycontainer2";
pContainer = new ProfileImpl( true);
pContainer.setParameter(Profile.CONTAINER_NAME,containerName);
System.out.println("Launching container "+pContainer);
containerRef = rt.createAgentContainer(pContainer);
AgentController Agent1 = containerRef.createNewAgent("robot" + String.valueOf(2), "package1.launch", new Object[] {2});
Agent.start();
}
}
the error showing is :
Exception in thread "main" jade.wrapper.StaleProxyException: Illegal access exception in createAgent() [nested java.lang.IllegalAccessException: Class jade.core.management.AgentManagementService$CommandTargetSink can not access a member of class package1.launch with modifiers ""]
at jade.wrapper.ContainerController.createNewAgent(Unknown Source)
There is an error in your code, you do not update the Profile of your containers and use the same Name for 2 different containers, which is wrong.
//create container1
String containerName="Mycontainer1";
ProfileImpl pContainer = new ProfileImpl(PLATFORM_IP, PLATFORM_PORT, PLATFORM_ID);
pContainer.setParameter(Profile.CONTAINER_NAME,containerName);
System.out.println("Launching container "+pContainer);
ContainerController containerRef = rt.createAgentContainer(pContainer);
//create container2
containerName="Mycontainer2";
pContainer = new ProfileImpl(PLATFORM_IP, PLATFORM_PORT, PLATFORM_ID);
pContainer.setParameter(Profile.CONTAINER_NAME,containerName);
System.out.println("Launching container "+pContainer);
containerRef = rt.createAgentContainer(pContainer);
For a running example with 3 containers, see : https://gitlab.com/startjade/startJade
I have a process that creates an application and application pool using the Server Manager object in the Microsoft.Web.Administration namespace, the application pool is created first and then the application, assigning the newly created app pool to the application, code below.
protected TResult UseServerManagerWrapper<TResult>(Func<ServerManager, TResult> func)
{
using (var serverManager = new ServerManager())
{
return func(serverManager);
}
}
Application creation function
public void CreateApplication(String siteName, String parentApplicationName, String organisationName, String applicationName, String applicationPoolName)
{
UseServerManagerWrapper(serverManager =>
{
var site = serverManager.Sites[siteName];
var newApplication =
site.Applications.Add(
GetApplicationPath(parentApplicationName, organisationName, applicationName),
this.GetGeneratedApplicationPhysicalPath(siteName, parentApplicationName, organisationName, applicationName));
newApplication.ApplicationPoolName = applicationPoolName;
serverManager.CommitChanges();
return true;
});
}
and app pool creation.
public Boolean CreateApplicationPool(String applicationPoolName)
{
return UseServerManagerWrapper(serverManager =>
{
var appPool = serverManager.ApplicationPools.Add(applicationPoolName);
appPool.ManagedPipelineMode = ManagedPipelineMode.Integrated;
appPool.ManagedRuntimeVersion = "";
serverManager.CommitChanges();
return true;
});
}
This all works fine, the only problem I have is that I have to go into the application folder and manually assign permissions for the application pool.
I can't see anything in the ServerManager documentation that can help me and I can't figure out a way to use the Directory.SetAccessControl Method to give an application pool permissions. Is there anyway to do this in code?
Apologies if I'm using wrong terminology or anything, I'm new to publishing in general. Let me know if you need anymore info.
Ok, so after a lot of searching and some trial and error I've found the resolution and it's nothing to do with the ServerManager object. First of all to get this to work in ASP.NET Core 2.1 (1.x/2.x) I needed the System.IO.FileSystem.AccessControl Nuget and the Namespaces below.
using System.Security.AccessControl;
using System.Security.Principal;
These give the ability to modify the ACL of files and folders and then the CreateApplication function becomes the below.
public void CreateApplication(String siteName, String parentApplicationName, String organisationName, String applicationName, String applicationPoolName)
{
UseServerManagerWrapper(serverManager =>
{
var site = serverManager.Sites[siteName];
var generatedPath = this.GetGeneratedApplicationPhysicalPath(siteName, parentApplicationName, organisationName, applicationName);
var newApplication =
site.Applications.Add(
GetApplicationPath(parentApplicationName, organisationName, applicationName),
generatedPath);
newApplication.ApplicationPoolName = applicationPoolName;
var dInfo = new DirectoryInfo(generatedPath);
var acl = dInfo.GetAccessControl();
var acct = new NTAccount($"IIS APPPOOL\\{applicationPoolName}");
acl.AddAccessRule(new FileSystemAccessRule(acct, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.NoPropagateInherit, AccessControlType.Allow));
dInfo.SetAccessControl(acl);
serverManager.CommitChanges();
return true;
});
}
The code between "newApplication.ApplicationPoolName = applicationPoolName" and "serverManager.CommitChanges()" gets the ACL from the newly generated directory giving the ability to modify it and reassign with a new FileSystemAccessRule.
I have a Console Application which is invoking SSIS Package.Below is the code which is working Fine.
public static void ExecuteSSIS_Staging()
{
DataAccessLayer objDAL = new DataAccessLayer();
LogManager_SSIS objlogM = new LogManager_SSIS();
String strDestinationFilePath = System.Configuration.ConfigurationManager.AppSettings.Get("FileDownloaded");
try
{
Package pkg;
Application app;
DTSExecResult pkgResults;
MyEventListener eventListener = new MyEventListener();
string staging_pkgLocation = System.Configuration.ConfigurationManager.AppSettings.Get("SSIS_Staging_Filepath").ToString();
app = new Application();
pkg = app.LoadPackage(staging_pkgLocation, eventListener);
pkgResults = pkg.Execute(null, null, eventListener, null, null);
if (pkgResults == Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success)
{
Console.WriteLine("Success");
}
else if (pkgResults == Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure)
{
string err = "";
foreach (Microsoft.SqlServer.Dts.Runtime.DtsError local_DtsError in pkg.Errors)
{
string error = local_DtsError.Description.ToString();
err = err + error;
}
throw new Exception("Error Occurred while executing the SSIS Staging package:" + err);
}
}
catch (Exception ex)
{
throw new Exception("SSIS Package Execution Failed:" + ex.Message.ToString());
}
}
Now I am in a position to Invoke this Package inside Foreach Loop.
static void Main(string[] args)
{
try
{
foreach (DateTime FileDate in SortedDates)
{
ExecuteSSIS_Staging(FileDate);
}
}
Catch(Exception ex)
{
}
}
I am getting Many Issues like
Could not load file or assembly 'Microsoft.SqlServer.ManagedDTS
and few other DLL reference error.
Can anyone suggest me, how can i invoke SSIS Package Inside Foreach loop. The main thing is, In my Local machine it is working obsolutely file. But When i deploy it in server, it is not.
The actuall issue is i have added
Microsoft.SQLServer.ManagedDTS.dll version 9.0
in one machine. When i tried to open it in other machine, some how DLL is refernced to
Microsoft.SQLServer.ManagedDTS.dll version 10.0 version.
I changed it again & executed. Now Working Fine.
I am writing a database application using Visual Studio 2012 with Entity Framework 5 and SQL Server 2008. I would like Entity Framework to impersonate a SQL Server user (i.e. user without a login). I have created a new constructor for the DB context MyDatabaseEntities which includes an argument for the name of the user to impersonate. Here is the code that I've written:
public partial class MyDatabaseEntities
{
private String _impersonateUser = null;
public MyDatabaseEntities(String impersonateUser)
: base("MyConnectionString")
{
_impersonateUser = impersonateUser;
this.Database.Connection.StateChange += Connection_StateChange;
}
void Connection_StateChange(object sender, StateChangeEventArgs e)
{
if (e.CurrentState == ConnectionState.Open && e.OriginalState != ConnectionState.Open)
{
using (var cmd = this.Database.Connection.CreateCommand())
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add(new SqlParameter("user", _impersonateUser));
cmd.CommandText = "EXECUTE AS USER = #user";
cmd.ExecuteNonQuery();
}
}
}
I had to add the check...
if (e.CurrentState == ConnectionState.Open && e.OriginalState != ConnectionState.Open)
...because the method Connection_StateChange method seems to execute even when the state hasn't changed. Then problem is that when I run the code twice,
public void RunSimpleQuery()
{
using (MyDatabaseEntities context = new MyDatabaseEntities("UserName"))
{
var result = context.TableName.ToList();
}
}
...Entity Framework throws a SqlException:
A severe error occurred on the current command. The results, if
any, should be discarded.\r\nA severe error occurred on the current
command. The results, if any, should be discarded.
Any ideas?
Update 1
I in my code above, I changed...
cmd.CommandText = "EXECUTE AS USER = #user;";
...to...
cmd.CommandText = "REVERT; EXECUTE AS USER = #user;";
...and I still get the same SqlException error.
The problem is that EF closes connection when it doesn't need it and returns it back to the pool. So when it executes some SQL again it request new connection from the pool where your event may not be initialized. But again I believe that you should try to solve this with manually controlling connection lifetime to have both benefit of connection pooling and be able to meet your requirements.
I know is an old question, but maybe will be useful for someone.
I did in a different way, using your code...
Instead of
Connection_StateChanged event
I create two methods in the same class:
public void ChangeUser(String sUser)
{
if(Database.Connection.State != ConnectionState.Open)
Database.Connection.Open();
using (var cmd = Database.Connection.CreateCommand())
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add(new SqlParameter("user", sUser));
cmd.CommandText = "EXECUTE AS USER = #user;";
cmd.ExecuteNonQuery();
}
}
public void Revert()
{
if (Database.Connection.State != ConnectionState.Open)
Database.Connection.Open();
using (var cmd = Database.Connection.CreateCommand())
{
cmd.CommandType = CommandType.Text;
cmd.CommandText = "REVERT;";
cmd.ExecuteNonQuery();
}
}
I use it before and after execute stored procedure,
using (var db = new MyDatabaseEntities())
{
db.ChangeUser(model.Username);
var result = db.Something();
db.Revert();
return result;
}
It works fine with SPs and it doesn't throw an exception even after many executions. If I could catch an event after command execute, maybe all be encapsulated on MyDatabaseEntities.
How to query Folder Size in remote computer through WMI and C#.
I need to find the each User's folder size in C:\Users in remote System through WMI.
I tried Win32_Directory , CMI_DataFile but not able to find the desired answer.
Please help!!
To get the size of a folder using the WMI, you must iterate over the files using the CIM_DataFile class and then get the size of each file from the FileSize property.
Try this sample (this code is not recursive, I leave such task for you).
using System;
using System.Collections.Generic;
using System.Management;
using System.Text;
namespace GetWMI_Info
{
class Program
{
// Directory is a type of file that logically groups data files 'contained' in it,
// and provides path information for the grouped files.
static void Main(string[] args)
{
try
{
string ComputerName = "localhost";
ManagementScope Scope;
if (!ComputerName.Equals("localhost", StringComparison.OrdinalIgnoreCase))
{
ConnectionOptions Conn = new ConnectionOptions();
Conn.Username = "";
Conn.Password = "";
Conn.Authority = "ntlmdomain:DOMAIN";
Scope = new ManagementScope(String.Format("\\\\{0}\\root\\CIMV2", ComputerName), Conn);
}
else
Scope = new ManagementScope(String.Format("\\\\{0}\\root\\CIMV2", ComputerName), null);
Scope.Connect();
string Drive= "c:";
//look how the \ char is escaped.
string Path="\\\\FolderName\\\\";
UInt64 FolderSize = 0;
ObjectQuery Query = new ObjectQuery(string.Format("SELECT * FROM CIM_DataFile Where Drive='{0}' AND Path='{1}' ", Drive, Path));
ManagementObjectSearcher Searcher = new ManagementObjectSearcher(Scope, Query);
foreach (ManagementObject WmiObject in Searcher.Get())
{
Console.WriteLine("{0}", (string)WmiObject["FileName"]);// String
FolderSize +=(UInt64)WmiObject["FileSize"];
}
Console.WriteLine("{0,-35} {1,-40}", "Folder Size", FolderSize.ToString("N"));
}
catch (Exception e)
{
Console.WriteLine(String.Format("Exception {0} Trace {1}",e.Message,e.StackTrace));
}
Console.WriteLine("Press Enter to exit");
Console.Read();
}
}
}