Edited to add solution:
changed to use the constructor that takes a Microsoft.Xrm.Client.CrmConnection rather that a String connection string and it works.
I used the crmsvcutil.exe to generate the data context for our crm environment. When I try to initialize the connection.
This line:
public CSIDataContext(global::System.String name)
: base(name)
throws this error:
Unable to load the connection string name 'Authentication Type=AD; Server=/rest of conn string is here/'
This code resides in a BizLayer class library project and is being called from a win form test project. If both the generated entities class and the calling code are in the same project, I don't get that error.
It sounds like you're passing the full connection string in the constructor rather than the name of the connection string in the connectionStrings node of the app.config/web.config.
The XRM connection string is very similar to an ADO.NET connection string in that it resides in the element in the app.config/web.config. So, you would normally place the full connection string into your config with a name like so:
<connectionStrings>
<add name="XrmConnectionString" connectionString="Authentication Type=AD; Server=http://server.com; User ID=Domain\Username; Password=P#$$w0RD"/>
</connectionStrings>
Then, when you want to initialize the XRM context, you just supply the connection string's name:
var dataContext = new XRMDataContext("XrmConnectionString");
Try that and see if it works for you.
Related
I have been using the following to connect to Redis without issue until today, now I have to explicitly state provide a database parameter because of this:
ArgumentOutOfRangeException
Specified argument was out of the range of valid values. Parameter name: db at StackExchange.Redis.ConnectionMultiplexer.GetDatabase(Int32 db, Object asyncState) at MyServer.MyClass..cctor()
This is the config I have been using:
private static Lazy<ConnectionMultiplexer> MyConnection = new Lazy<ConnectionMultiplexer>(() =>
{
return ConnectionMultiplexer.Connect(MyRedisConnString);
});
public static ConnectionMultiplexer ConnGer
{
get
{
return MyConnection.Value;
}
}
and at class level:
private static readonly IDatabase RedisDb = RedisConfig.ConnGer.GetDatabase();
Providing the db parameter thus:
RedisConfig.ConnGer.GetDatabase(0);
fixed the error of course; more of a concern is whether there have been any seeming breaking changes recently as my class libraries are littered with Redis!
UPDATE
After thinking I had resolved the issue, for no apparent reason the ConnectionMultiplexer started failing again with the above config. I tried defaultDatabase=0 in the string and also tried as a Configuration.Option and got this error:
Exception type: ArgumentException
Exception message: Keyword 'defaultDatabase' is not supported
at StackExchange.Redis.ConfigurationOptions.OptionKeys.Unknown(String key)
at StackExchange.Redis.ConfigurationOptions.DoParse(String configuration, Boolean ignoreUnknown)
at StackExchange.Redis.ConnectionMultiplexer.CreateMultiplexer(Object configuration)
at StackExchange.Redis.ConnectionMultiplexer.ConnectImpl(Func 1 multiplexerFactory, TextWriter log)
at System.Lazy1.CreateValue()`
and with the ConfigOption mode:
Exception type: TypeInitializationException
Method not found: 'Void StackExchange.Redis.ConfigurationOptions.set_DefaultDatabase(System.Nullable 1<Int32>)'.
I also removed the System.Lazy part of the config too, same errors.
Putting the 0 value in as a GetDatabase() parameter stopped the error for now; the concern remains that this doesn't match the documented implementation.
You are probably specifying a wrong default database in the config?
Try adding defaultDatabase=0 to your connection string.
See the configuration options.
This is a bit of an old one, but I just experienced it out of the nowhere. The server rebooted from a windows update and then the errors began occurring whilst they'd been running fine for a very long time.
To fix it, I just updated to the latest version of the dll.
I really appreciate any insight anyone can provide.
I've come back to a project that was using the EF6.0 rc preview. After updating the projects EF to 6.1 and updating the SQL Server CE I have two problems.
[UPDATE]
Problems 1 & 2 solved Problem 3 is not.
PROBLEM 3 -
Now with the path set via a connection string as explained above, migrations called via the package manager are not working as its an invalid path. Any ideas anyone?
When I start up the debug process, I get problem 1 and the exceptions crash; but it does create a .sdf file although in the wrong location as explained in problem 2.
1. NOT MAPPED PROPERTY AND UNSUPPORTED BY LINQ ERROR
During the initial creation process I get an exception
List<Equipment> duplicateTags = db.EquipmentReg
.GroupBy(e => e.TagAndLocation)
.Where(g => g.Count() > 1)
.SelectMany(g => g).ToList<Equipment>();
The exception is related to the TagAndLocation. TagAndLocation is defined in the model by
/// <summary>
/// Creates concatenation object that will not be mapped in the database but will be in the
/// Object Relational Mapping (ORM) of the EF model.
/// </summary>
[NotMapped]
public string TagAndLocation { get { return Tag + " (" + Location.Name + ")"; } }
A first chance exception of type 'System.NotSupportedException' occurred in EntityFramework.dll
Additional information: The specified type member 'TagAndLocation' is
not supported in LINQ to Entities. Only initializers, entity members,
and entity navigation properties are supported.
Why is this happening now?
2. CONNECTION STRING NOT APPLYING LOCATION
My connection isn't applying the path properly anymore.
I have it being done by a DbConfiguration class which auto runs, I guess due to its inherited class type. As shown below
class HAIDbJob_EFConfiguration : DbConfiguration
{
public HAIDbJob_EFConfiguration()
{
SetProviderServices(SqlCeProviderServices.ProviderInvariantName, SqlCeProviderServices.Instance);
// Create the connection string programmatically - Setting the filename and path.
SetDefaultConnectionFactory(new System.Data.Entity.Infrastructure.SqlCeConnectionFactory(
"System.Data.SqlServerCe.4.0",
System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Databases"),
#"Data Source=" + System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Databases") +
#"\Hazardous_Area_Database_Job.sdf"));
}
}
Instead of creating a file in the runtime location ...\bin\Debug\Databases\Hazardous_Area_Database_Job.sdf, it creates it at
..\bin\Debug\HA_Inspector.HAI_Database.HAI_Job_EF_Model.Hazardous_Area_Database_Job.sdf
Which is the full namespace of the database model... I have tried a few solutions found for other people problems of a slightly different nature, but none of it works. Any ideas would be extremely appreciate.
1: The EF provider attempt to translate TagAndLocation to SQL and fails. You must use LINQ to Objects for this grouping.
2: Why not have a named connectionstring in your app.config, or pass it in the DbContext constructor.
SOLUTION 1
I did a string compare in the group by statement since location has a string member Location.Name.
SOLUTION 2
When I originally wrote this I wanted to dynamically name the database all the time and this is why I wrote the initialiser class.
To get around the problem, I just followed Erik's advice and put a XAML connection string in app.config using "Source=./Databases"..... to get the subfolder.
I am successfully exposing a method using the Spring annotations:
#Override
#ManagedOperation(description = "synchronize To Local Directory")
#ManagedOperationParameters({ #ManagedOperationParameter(name = "localDirectory", description = "The Local Directory") }
public void synchronizeToLocalDirectory(File localDirectory) {
super.synchronizeToLocalDirectory(localDirectory);
}
By successful I mean that it can be seen in jConsole.
However, the operation cannot be invoked, obviously because the parameter; localDirectory, needs to be specified.
localDirectory is of type File.
The problem is that the button/option to set the localDirectory in the invocation of the operation is not active.
If I change the type from File to String it works, but I do not want to do that - I preferably want the user to choose a directory via a file chooser dialog.
Questions:
Does JMX cater for a File type parameter in a operation that can be specified in something like jConsole? Or does it have to be setup as a Composite type?
Thanks
No java.io.File is not a directly supported JMX type. As you are correctly suggesting you need to either use a composite type or adjust the management interface to accept eg. String value of the file path.
I want to read my connection strings from the Web.config or App.Config file. I attempted to follow the advice in another Stackoverflow post.
The suggestion was to:
Set Application Settings in the Linq to Sql DBML file to false. (Double-click on the Linq to Sql file to open it, right-click on white space in the designer surface, select Properties, expand Connection property. )
Set Connection to (None) in the Linq to SQL DBML file.
Add an OnCreated event method in the data context partial class to read the connection string from web.config or app.config.
When I make the above changes and attempt to compile my code I get:
Error 2 Expression of type 'Object' is not queryable. Make sure you are not missing an assembly reference and/or namespace import for the LINQ provider.
The error occurs on the 2nd line below:
Using DcObj = New HMR_LinqToSql_QuestionDataContext()
Dim Query = From Q In DcObj.tblQuestions Select Q ' *** Error on this line
Count = Query.Count()
DcObj.tblQuestions.DeleteAllOnSubmit(Query)
DcObj.SubmitChanges()
End Using
The only way, I found, to clear the error is to set Application Settings to True and select a connection string entry in the Connection drop down list. If I revert to Application Settings = True that mean there is still connection strings in the Linq to Sql files.
Any ideas for a solution?
Ed
I'm trying to figure out how to create a dynamic context, and what I mean by that is I have two databases: one for testing, and one for production. Depending on where my website is hosted, I want my context to be pointing at one of the two. So, in my web.config I have:
<add name="Testing_ChannelsEntities" connectionString="removed for brevity" providerName="System.Data.EntityClient" />
<add name="Production_ChannelsEntities" connectionString="removed for brevity" providerName="System.Data.EntityClient" />
Please don't get hung-up on the fact that I removed the connectionString for this example. Just note that I have a testing and a production connection in the web.config.
So, here is my codebehind that I would expect to create a context to the testing connectionString:
using (ChannelsEntities chEntity = new ChannelsEntities("Testing_ChannelsEntities")) {
// removed the business logic because it's not relevant at all
}
Once execution hits the using statement, I get the following error:
Format of the initialization string does not conform to specification starting at index 0.
What am I missing here? This should be easy to do.
I've done similar. Try this -
using (ChannelsEntities chEntity = new ChannelsEntities("name=Testing_ChannelsEntities")) {}
Try:
using (ChannelsEntities chEntity = new ChannelsEntities(WebConfigurationManager.ConnectionStrings["Testing_ChannelsEntities"].ConnectionString)) {
// removed the business logic because it's not relevant at all
}
We put our connection string in a root web.config. You can reference the connection string by name in your virtual diectory and it will inherit the settings from your root web.config.