Hello I'm trying to use SMO to create an exact copy of one DB in the same server. I'm able to copy the schema, the data and the users, but I just noticed that the roles for the users are not copied between the databases. Their roles look like this:
Original DB
Cloned DB
My current transfer object configuration looks like this:
Transfer t = new Transfer(database);
t.Options.DriAll = true;
t.CopySchema = true;
t.CopyData = true;
t.CopyAllDatabaseScopedCredentials = true;
t.CopyAllRoles = true;
t.CopyAllUsers = true;
t.PreserveDbo = true;
t.PreserveLogins = true;
t.DestinationServer = connection.DataSource;
t.DestinationDatabase = dbname;
t.TransferData();
But the roles are not copied, and because of that, when the user tries to read/write anything I get the 'Log in failed' error for that user, is there a config that I'm missing? Or is this not possible using SMO?
Thanks for the help!
Try t.Options.IncludeDatabaseRoleMemberships = true
Related
I am very new in SharePoint (I am using SharePoint 2013) and I am experiencing a strange problem. This is very strange because in another section of my application it works fine (in another subsite).
So basically into SharePoint I have a SharePoint list named Protocollo.
My code contains the following lines that add a document (a file) into a subfolder of the previous SharePoint List:
internal static int InsertItem(Dictionary<string, object> prot, Documento doc, bool assignVisibility, bool newItem)
{
int state = 0;
SPListItem item = null;
UOR currUOR = null;
List<UOR> path = new List<UOR>();
SPWeb web = SPContext.Current.Web;
string siglaAOO = web.Properties["sigla_aoo"];
DBConnection dbConfig = ArxeiaProtocollo.Util.ProtUtils.InitializeDBConnection();
dbConfig.Database = siglaAOO;
string username = web.CurrentUser.LoginName;
try
{
SPList list = web.Lists["Protocollo"];
web.AllowUnsafeUpdates = true;
SPFolderCollection folders = list.RootFolder.SubFolders;
SPFolder annoFolder;
DateTime dateProt = Convert.ToDateTime(prot["Data protocollo"]);
try
{
annoFolder = folders[dateProt.Year.ToString()];
}
catch
{
annoFolder = folders.Add(dateProt.Year.ToString());
}
SPFolder meseFolder;
try
{
meseFolder = annoFolder.SubFolders[dateProt.Month.ToString("D2")];
}
catch
{
meseFolder = annoFolder.SubFolders.Add(dateProt.Month.ToString("D2"));
}
SPFolder dayFolder;
try
{
dayFolder = meseFolder.SubFolders[dateProt.Day.ToString("D2")];
}
catch
{
dayFolder = meseFolder.SubFolders.Add(dateProt.Day.ToString("D2"));
}
SPFile spFile = dayFolder.Files.Add(doc.Nome, doc.File, true);
............................................................
............................................................
............................................................
}
As you can see the previous code retrievce the Protocollo list from the current website allowing updates on it by:
SPList list = web.Lists["Protocollo"];
web.AllowUnsafeUpdates = true;
Then into this list it creates (it doesn't exist) a gerarcic folders structure for year (annoFolder), month (meseFolder) and day (dayFolder).
It works fine, I tried to delete these folder structure from my SharePoint site and performing this method it is created again, infact this is what I obtained:
As you can see it correctly creates this folder structure into my SharePoint list (named Protocollo) into the current website.
Ok finnally my code try to insert a document into the last subfolder (the dayfolder) by:
SPFile spFile = dayFolder.Files.Add(doc.Nome, doc.File, true);
I am passing to the Add() method: the name of the file, the byte array representing the file and the true boolean value.
The problem is that performing this line I obtain the following exception that is not providing information:
{Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.}
Then in my front end it appears a "denied access" popup window.
The strange thing is that another sites in my SharePoint that uses the same code have no problem. Another strange thing is that manually uploading the file into this location of the list it works fine so I think that it should not be a user permission problem.
Some idea? What can I try to do to solve this strange problem?
SharePoint codes run using the Application Pool user in IIS not the user that you have logged in to SharePoint, so it is common to get an access denied error even when you have access. So I would suggest you check the permission for the AppPool account on the Protocollo library. Or you can use SPSecurity.RunWithElevatedPrivileges if you have trust in the user that will run the code.
Beware of the pitfalls though.
Here is a sample usage:
Guid siteId = SPContext.Current.Site.ID;
Guid webId = SPContext.Current.Web.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(siteId))
{
using (SPWeb web = site.OpenWeb(webId))
{
// Your code here
}
}
});
I have created mvc application.. In that i have write code for update web.config.i.e
try
{
//// Helps to open the Root level web.config file.
Configuration webConfigApp = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
AppSettingsSection objAppsettings = (AppSettingsSection)webConfigApp.GetSection("appSettings");
//Edit
if (objAppsettings != null)
{
////Modifying the AppKey from AppValue to AppValue1
objAppsettings.Settings["DaysToKeepJob"].Value = model.Keepjobsfolders.ToString();
objAppsettings.Settings["DeleteLocalStoreStudies"].Value = model.DeleteLocalStoreStudies.ToString();
objAppsettings.Settings["ManualBurnerNoOfCopies"].Value = model.ManualNumberofCopies.ToString();
objAppsettings.Settings["DefaultBurner"].Value = model.DefaultBurner.ToString();
objAppsettings.Settings["AutoBurnerNoOfCopies"].Value = model.AutoNumberofCopies.ToString();
objAppsettings.Settings["SmartDisk"].Value = model.chkSMARTDisk.ToString();
objAppsettings.Settings["ForcetodefaultTransfer"].Value = model.chkKeepjobsfolders.ToString();
////Save the Modified settings of AppSettings.
webConfigApp.Save();
}
if (diskType.Title != null)
{
var res = DiskTypeSave(diskType);
}
return Json(new { Status = "Success", Msg = "Rules Saved Successfully." }, JsonRequestBehavior.AllowGet);
}
but after this line webConfigApp.Save(); my session i.e Session["UserAccessRights"] get null . i know because of updating web.config it get null.
Please suggest to maintain session even web.config updates
Every time you change the web.config the application is restarted in IIS.
You can do one of the things below :
Use another settings file, a xml, json, etc. to store those values
Use the database to store those settings per user
Use SQL server for saving sessions or a state server, not in-memory (default)
For this you first have to keep Sessions copy into local variable and then assign again. But for this you have to keep Session.SessionId copy also, because on new session it sets again.
I'm trying to add a role to my SSAS DB, but I'm having issues when I try to set the database permissions.
The following code will run without error
var server = new Microsoft.AnalysisServices.Server();
server.Connect("localhost\\SQLSERVER2012");
var database = server.Databases["LRTabDB"];
var role = database.Roles.Add(database.Roles.GetNewName("DataHubRole"));
var databasePermission = new Microsoft.AnalysisServices.DatabasePermission
{
RoleID = role.ID,
ID = role.Name,
Name = role.Name,
Read = Microsoft.AnalysisServices.ReadAccess.Allowed
};
database.DatabasePermissions.Add(databasePermission);
var member = new Microsoft.AnalysisServices.RoleMember { Name = "NETWORK SERVICE" };
role.Members.Add(member);
role.Update();
databasePermission.Update();
database.Update();
But when I attempt to look at the Role in SQL Server Management Studio I get the following error message
Cannot show requested dialog.
Additional information:
Key cannot be null.
Parameter name: key (System)
If I remove the creation of the databasePersmisson object then I can view the role in Management Studio. But ultimately I need to set the database permissions for the role. I've also attempted getting the permissions, but the following just returns null.
database.DatabasePermissions.FindByRole(role.ID);
I've also tried using the following to create the database permissions and got the same results.
var databasePermissions = database.DatabasePermissions.Add(
database.DatabasePermissions.GetNewName(role.Name));
Finally I've also tried using a different Name and ID for the database permission from the role but again that does not help.
I assume there is some step that I'm missing, but the examples I've found for doing this don't shed any light on the problem.
https://bennyaustin.wordpress.com/2011/05/24/ssas-using-amo-to-secure-analysis-service-cube/
I don't know how can I get your error, but I've done something, what works for me.
Here is the code:
Server server = new Server();
server.Connect("Data source=" + cubeServerName + ";Timeout=7200000;Integrated Security=SSPI;");
Database db = server.Databases.FindByName(cubeName);
if (db.Roles.Find("MyRole") == null)
{
Role newRole = db.Roles.Add("MyRole");
RoleMember r = new RoleMember(userDomain + "\\" + userName);
newRole.Members.Add(r);
newRole.Update();
}
DatabasePermission dbperm;
var role = db.Roles.Find("MyRole");
dbperm = db.DatabasePermissions.Add(role.ID);
dbperm.Process = true; //I want to add process permission
dbperm.Update();
I used tutorial from msdn.
I'm working on an internal portal that allows users to request accounts to various other domains we manage.
I have to check if a certain account already exists via LDAP, so this is what I do to make a connection.
const string server = "ldap.mydomain.net:636";
using (var ldapSSLConn = new LdapConnection(server))
{
var networkCredential = new NetworkCredential("user", "supersecurepassword");
ldapSSLConn.SessionOptions.SecureSocketLayer = true;
ldapSSLConn.AuthType = AuthType.Basic;
ldapSSLConn.SessionOptions.SecureSocketLayer = true;
ldapSSLConn.SessionOptions.VerifyServerCertificate = new VerifyServerCertificateCallback((con, cer) => true);
ldapSSLConn.Bind(networkCredential);
// Search happens here
// Return results
}
I can then use the ldapSSLConn to search for existing accounts.
Everytime I need to make a connection, it takes me +/- 20 seconds, the search itself 85ms.
Is there a way I can cache the connection? For example open it on Application_Start(), and then reference it when I need it?
I found a solution that works for me.
I'm checking if a connection is cached now, with;
if (System.Web.HttpContext.Current.Cache["LDAPConnection"] == null)
If it isn't, I make a connection (see question), and at the end, cache it:
System.Web.HttpContext.Current.Cache.Add("LDAPConnection", ldapSSLConn, null, DateTime.Now.AddHours(8), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.High, null);
I have a small C# console program that retrieves an item list from quickbooks, and I am trying to figure out how to expose that data to Microsoft Access. It is in XML format.
I want to retrieve the data in real-time, since it only takes about a second to get the data, whenever Access calls for it. I am using Access 2003 and VS 2010.
If there is a way to do this with VBA that would work fine as well. I can get the XML data using VBA already, but I don't know how to go from there.
Here is the code I use in C#:
public string DoQBQuery(XmlDocument doc)
{
bool sessionBegun = false;
bool connectionOpen = false;
RequestProcessor2 rp = null;
string ticket = "";
try
{
//Create the Request Processor object
rp = new RequestProcessor2();
//Connect to QuickBooks and begin a session
rp.OpenConnection2("", "QB Transaction Item Retriever", QBXMLRPConnectionType.localQBD);
connectionOpen = true;
ticket = rp.BeginSession("", QBFileMode.qbFileOpenDoNotCare);
sessionBegun = true;
//Send the request and get the response from QuickBooks
string responseStr = rp.ProcessRequest(ticket, doc.OuterXml);
//End the session and close the connection to QuickBooks
rp.EndSession(ticket);
sessionBegun = false;
rp.CloseConnection();
connectionOpen = false;
return responseStr;
}
catch (Exception e)
{
MessageBox.Show(e.Message, "Error");
if (sessionBegun)
rp.EndSession(ticket);
if (connectionOpen)
rp.CloseConnection();
throw;
}
}
"I am trying to figure out how to expose that data to Microsoft Access. It is in XML format"
I've never tried this before, but I think this is possible by putting the c# classes that accomplish what you discussed in a dll and calling from Access. Here is a post from this site about that.
A Simple C# DLL - how do I call it from Excel, Access, VBA, VB6?
P.S. Given I've never tried this before, I would have put this in the comment section of your original post, but I'm new to this site and am unable to do that.