My program hangs when it gets values using Entity Framework. Here is my simple code:
LearningEnglishEntities db2 = new LearningEnglishEntities();
List<tb_Words> searchedItems = db2.tb_Words.ToList(); // it hangs here
It's not an async method. There are solutions about async but I didn't find any solution to fix my problem.
It doesn't respond, it's waiting forever. All my code was running until 2 days ago. I didn't type or do anything and this bug happened (short video is here)
I have tried these things so far:
I removed Entity Framework model from my solution and I added it again
I created a new program and I used exactly same codes and model (it worked):
LearningEnglishEntities1 db = new LearningEnglishEntities1();
List<tb_Words> sample = db.tb_Words.ToList(); // It worked
I cleaned my solution
I typed this code:
var query = from item in db.tb_Words select item; // It hangs the same way
I checked this code is not run by another thread:
bool query0 = this.InvokeRequired;
if (!query0)
{
LearningEnglishEntities db2 = new LearningEnglishEntities();
List<tb_Words> searchedItems = db2.tb_Words.ToList(); // It still hangs
}
I changed my Entity Framework 6.0x version to 5.0x but it didn't
work.
I completely copied all files and pasted to a new project. It ran but it didn't work
I restarted Microsoft Distributed Transaction Coordinator Service and checked startup type is Automatically. It didn't work.
Strangely, it works on other projects but it hangs on this project. I haven't found any solution to fix this bug. Do you think what should i do?
Also My Connection String is :
<connectionStrings><add name="LearningEnglishEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=DESKTOP-REKGVD4\SQLEXPRESS;initial catalog=LearningEnglish;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings>
Thank you
After all things, I was able to find a solution but I don't know the reason. Using Entity Framework Code First solved my problem. It is not good for my project but i have to use it.
Related
I'm going through the mongoDB Driver Documentation Quick Tour for the first time. Specifically the 2.4 version.
I've created a fresh mongodb instance at the 192.168.1.50 address, and it appears to be running correctly.
The MongoDB documentation gives the following example:
var client = new MongoClient("mongodb://192.168.1.50:27017");
#It's ok if the database doesn't yet exist. It will be created upon first use
var database = client.GetDatabase("testDB");
#It’s ok if the collection doesn’t yet exist. It will be created upon first use.
var collection = database.GetCollection<BsonDocument>("testCollection");
However, when I go on my server, and I enter the mongo console
mongo
And I list the databases using
show dbs
The output is only
admin 0.000GB
local 0.000GB
Is there anything else I should have done to make this work? I'm getting no errors on try/catch, and it appears to be running fine.
Troubleshooting
So far I've confirmed that mongodb is running by using the following:
netstat -plntu
Shows mongod running on 27017 in the LISTEN state.
I'd also be interested in knowing if there's a way on the mongodb server to view live connections, so I could see if it were actually successfully connecting.
Well the problem is that you need to create almost one collection in order to persist the created database (weird right?) i tested it with robomongo and works in that way.
The problem is that GetCollection method is not creating the target collection, you can try with this code:
static void Main(string[] args)
{
var client = new MongoClient("mongodb://192.168.1.50:27017");
//# It's ok if the database doesn't yet exist. It will be created upon first use
var database = client.GetDatabase("test");
//# It’s ok if the collection doesn’t yet exist. It will be created upon first use.
string targetCollection = "testCollection";
bool alreadyExists = database.ListCollections().ToList().Any(x => x.GetElement("name").Value.ToString() == targetCollection);
if (!alreadyExists)
{
database.CreateCollection(targetCollection);
}
var collection = database.GetCollection<BsonDocument>(targetCollection);
}
It turns out that a method I had found on how to set multiple bindIp's was incorrect. The problem wasn't with the C# at all. I found the solution here
In case that ever goes away, here's the current settings I had to follow for multiple ip's
edit file /etc/mongod.conf
Wrap the comma-separated-Ips with brackets
bindIp = [127.0.0.1, 192.168.184.155, 96.88.169.145]
My original code worked fine, I just didn't have the brackets on the bindIp.
I am currently going through the process of upgrading our product CRM SDK and the main change I have encountered is that instead of connecting to the Xrm service and creating my IOrganizationService using the tried and trusted method of:
var connection = CrmConnection.Parse(connectionString);
var service = new OrganizationService(connection);
I am now having to utilise the CrmServiceClient from the Tooling namespace:
CrmServiceClient conn = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connectionString).OrganizationServiceProxy;
Now this is all fine except from one major issue...memory.
Using the older Xrm.Client method you were able to specify the Service Configuration Instance Mode (which defaulted to ServiceConfigurationInstanceMode.PerName). What this meant is that the service was reused if the same application called the create multiple times. This kept the memory footprint low. The below image show the amount of allocated memory after calling to create a service instance 100 times
However, using the newer method you cannot set this instance mode anywhere and it seems that a brand new connection is created every time whether you want it or not. Here are the results of the same test:
As you can see, with every new connection, more and more memory is allocated. I can;t see anywhere that i can tell it to reuse the service.
So what I'm basically asking is, am I going about this in the wrong way? Should I be creating and caching everything myself? Are there hidden classes/methods that I am missing? Any help would be greatly appreciated.
The latest SDK (8.2.0.1) caches and resuses the connection as long as the connectionstring does not inclue RequireNewInstance=true.
One thing worth noting is even if you new up another CrmServiceClientwith a unique connection string (pointing to a different CRM organization), but the connection string does not include RequireNewInstance=true, the CrmServiceClient will reuse the previous cached connection.
So
var connectionString = $#"Url=https://ORG1.crm.dynamics.com;AuthType=Office365;UserName=USER#DOMAIN.com;Password=PASSWORD";
var connectionString2 = $#"Url=https://ORG2.crm.dynamics.com;AuthType=Office365;UserName=USER#DOMAIN.com;Password=PASSWORD";
var crmSvcClient = new CrmServiceClient(connectionString);
((WhoAmIResponse)crmSvcClient.Execute(new WhoAmIRequest())).OrganizationId.Dump();
crmSvcClient.ConnectedOrgFriendlyName.Dump();
var crmSvcClient2 = new CrmServiceClient(connectionString2);
((WhoAmIResponse)crmSvcClient2.Execute(new WhoAmIRequest())).OrganizationId.Dump();
crmSvcClient2.ConnectedOrgFriendlyName.Dump();
Prints out the guid and ORG1 friendly name both times. If you pass RequireNewInstance=true in connectionstring2 then you will see ORG2 printed out.
I want to change the query in table adapter but it's not opening & throwing an error "Configure table Adapter Failed" & in property of connectionString it says "Unable to find connection 'ConnStringName' for object 'Web.config'. The connection string could not be found in application settings, or the data provider associated with the connection string could not be loaded"
I have been looking for a solution for this problem for a long time. Thankfully I found a solution that worked for me.
Close the dataset window with the error.
Right click the dataset in the solution explorer.
Select “Open with…” from the context menu.
Select “Source Code (Text) Editor” from the list and press the “OK”
button.
Near the top of the file, you’ll see a element with several elements within it. Most datasets should only have one element. If you are having trouble like I’ve described above, you’ll have at least two and one will be incorrect. Delete it or otherwise fix it, save the file and reopen normally.
This is the page where I found it out.
See the complete answer here
I faced the same problem which is actually a nightmare and triyed Lorena solution and it was not enough to solve the problem.
The missing part is to modify the Dataset using the XML editor changing the DefaultConnectionIndex to be 0 like this:
<DataSource DefaultConnectionIndex="0"
FunctionsComponentName="QueriesTableAdapter" Modifier="AutoLayout, AnsiClass,
Class, Public" SchemaSerializationMode="IncludeSchema" xmlns="urn:schemas-
microsoft-com:xml-msdatasource">
thanks to Don who pointed this
https://social.msdn.microsoft.com/Forums/windows/en-US/08a48cad-619d-4421-b584-f2b5550ba6c5/dataset-designer-quotunable-to-find-connection-myconn-mysettings1-for-object-mysettingsquot?forum=winformsdatacontrols
Seems like there no ConnStringName parameter in connectionString section of Web.config
<connectionStrings>
<add name="ConnStringName" providerName="" connectionString=""/>
</connectionStrings>
Updated:
The problem is in missing reference to System.Data.OracleClient. To solve this just add reference on missing provider.
Well Same problem I faced in Windows Forms, I just opened Settings.settings file, found the "ConnectionString" and repaired it.
(As you click in Value field of ConnectionString a button [...] appears in last of Value field click it and repair/test your connection again, in my case I re-entered password again.) .
Hope This Helps.!
ConnStringName is case-sensitive.
I'm trying to add one object to database table using this code, in my console application:
using (var context = new Database1Entities())
{
var number = new Numbers()
{
Num=15
};
context.Numbers.AddObject(number);
context.SaveChanges();
Console.WriteLine(number.Id);
Console.ReadLine();
}
My model:
Connection string:
<connectionStrings>
<add name="Database1Entities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\Database1.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
packages.config:
<packages>
<package id="EntityFramework" version="6.1.0" targetFramework="net40-Client" />
</packages>
but it does not add any thing to database and whenever it runs, it returns 1 as Id of stored Number.
As Abhay Prince said: There is no any syntactical or logical error or mistake in this code.
Problem: I should say that always changes which program do on mdf file was on file that automatically copied to bin/debug folder; so when I check my mdf file that is reachable in Visual Studio, it does not have any changes affected by application.
There is no any syntactical or logical error or mistake in your code. It should work perfectly, if it is not giving desired output, try clean your project or restart your Visual Studio may be it is due to cache or log data.
Try restart your Visual Studio and let we know if it works correct or not..
Try
context.Numbers.AddObject(number);
context.Entry(number).State = EntityState.Added;
context.SaveChanges();
If I understand this correct
What is difference between dbcontext.Add and dbcontext.AddObject
then you need to set manually that the context has been changed before it can save to database.
If you instead use
context.Numbers.Add(number);
The context should automatically set that the context has changed and the savechanges should work.
put SaveChanges() in try catch
it captures the SaveChanges() error.
I have a Sqlite database that I include with my MonoTouch app. It has worked fine for me so far, but now I want to open it in read-only mode rather than read-write.
So I have changed the connection string to include 'Read Only=True', but when I call Open(), I get the following error:
Library used incorrectly (at Mono.Data.Sqlite3.Open)
If I dig into the exception it shows
_errorCode = Misuse
and that's about all the info it gives.
Here's the code:
var _conn = new SqliteConnection("Data Source=db/sampleDb;Read Only=True");
_conn.Open ();
You found a bug in Mono.Data.Sqlite.dll.
The Create flag is appended (by default) before the ReadOnly flag is parsed and set. The resulting flag is invalid and sqlite reports an error.
I will fix this for future releases (of Mono and MonoTouch...). If this blocks you then please open a bug report on http://bugzilla.xamarin.com and I'll attach a fixed assembly (with instructions to replace the existing one) to the bug report.
This worked for me (aspnet core):
var _conn = new SqliteConnection("Data Source=db/sampleDb;mode=ReadOnly");
Have you tried?:
var _conn = new SqliteConnection("Data Source=db/sampleDb;mode=ro");
Your code is correct, I just tried it (not using MonoTouch) and it worked for me.
Do you have the latest version of System.Data.SQLite.dll?
If yes, then maybe it's a problem related to MonoTouch.