I am trying to apply a sql query on different databases on several servers but I have an error when thrying to connect with dynamic connection manager datasource. Workflow :
I am able to iterate through the foreach but I am not able to apply the query to all the Server/DB configurations.
I am using a dynamic datasource set by variable in an expression.
My connection string is strctured like this : Data Source=SrvName;Provider=SQLNCLI11.1;Integrated Security=SSPI;Auto Translate=False;Initial Catalog=DB1;User Id=Usr;Password=Pwd;
My "Source" in connection manager is set with a ConnectionString Property with the whole connection string contained in my ConStr Variable as expression (#[User::ConStr]).
Error message is : Failed to acquire connection "Source" conenction may not be configured correctly or you may not have the right permissions ...
I don't know why I am not able to connect to apply the query to the different databases. Thanks in advance for your help.
Related
I want to use the SqlEntityConnection type provider in f# to query and update a db.
It works well when I use it with the connection string pointing to a live SQL Server DataBase.
type EntityConnection = SqlEntityConnection<"Data Source=myServer;Initial Catalog=myDb;...", Pluralize=true>
Now I want to get rid of the dependency with the live DB and, instead, use a local schema file. Given what I read on msdn, I gave a try to the following line:
type private EntityConnection = SqlEntityConnection<LocalSchemaFile="mySchemaFile.ssdl", Pluralize=true>
Unfortunately, it doesn't compile and the compiler's message is:
Error 46 The type provider 'Microsoft.FSharp.Data.TypeProviders.DesignTime.DataProviders' reported an error: When using this provider you must specify either a connection string or a connection string name. To specify a connection string, use SqlEntityConnection<"...connection string...">.
So what should I do? If I leave the connection string, I have the feeling that I don't really turn off the dependency to the DB. For instance, if I try to switch the Data Source with a non-existing server, it doesn't compile.
You can provide a connection string name, along with a connection string in the configuration file.
You can still provide a localschemafile that will be used to cache locally the schema.
If you put the schema file under source control, the connection string will only be used as a default when calling GetDataContext() without parameter, but not when building or editing code.
You also need to set the parameter ForceUpdate to False.
I need to get some data from a different database (different server, actually), so I've created a second datacontext pointing to a second Breeze controller, repository, and edmx. I also created second model and entityManagerFactory since data I'll need to be getting is substantial and wanted to separate it from the base functionality. In my new EntityManagerFactory, if I have:
breeze.NamingConvention.none.setAsDefault();
all works well, but I don't get camel casing. If I have:
breeze.NamingConvention.camelCase.setAsDefault();
or if I don't call it at all (since it's just setting the app-wide default which is already set) I get this error:
[myDatacontext] [HT Error] Error retrieving dataMetadata query failed for: breeze/Vsp/Metadata. Unable to either parse or import metadata: NamingConvention for this server property name does not roundtrip properly:name-->Name; [object Object]Error: Metadata query failed for: breeze/Vsp/Metadata. Unable to either parse or import metadata: NamingConvention for this server property name does not roundtrip properly:name-->Name; [object Object]
There's not even a "name" or "Name" property on class I'm getting.
What am I missing?
By the way, I do get the metadata from the server. The client just doesn't like it.
I suppose that since you've posted this you found a solution.
But I also had this problem, it is because I use Entity-Framework ADO .Net 6.0, it takes into account stored procedure, views or tables that are not camelcase, so you have to unselect them before generating the model / context.
I am using EF code first model to get the data from data base table in which i have 400,000 records.
But when i use the LINQ query something like:
var urer = context.UserEntity.Where(c => c.FirstName.Contains('s'));
The above statement gives me all the user to whose first name contains 's'. But since this is a huge data base table, it is giving me the following error:
An existing connection was forcibly closed by the remote host
Please suggest me the best way to do it. I am assigning this data to gridview. I am thinking to get the first 500 each time. Is there any way to do it from EF side, so that i won't need to do it in sql.
Thanks
1.add index on your column
2. increase timeout connection
You can create Store procedure
USE LINQ call Store procedure
LINQ to SQL (Part 6 - Retrieving Data Using Stored Procedures)
http://weblogs.asp.net/scottgu/archive/2007/08/16/linq-to-sql-part-6-retrieving-data-using-stored-procedures.aspx
See this answer as well
Calling a SQL Server stored procedure with linq service through c#
Get rid of EF
set key in web.config common key for timeout replace 600
try
{
conn.Open();
mySqlCommand.Connection = conn;
mySqlCommand.CommandTimeout=600;
I found the "OnQueryStatement" method :
procedure TkbmMWQueryService2.kbmMWQueryServiceQueryStatement(Sender: TObject;
Place: TkbmMWQueryOperationType; var NamedQueryName, Statement: string);
begin
Form1.Memo1.Lines.Add(Statement);//show the query statement
end;
this method can get the client-side query statement,but all the client-side query trigger this event twince!(like the screenshot)!Why? How can i get the client-siade query statement correctly?
thanks in advance! :)
Its called twice on the server (in fact can be called 3 times for the same query on the server in the most far out situation).
Check the Place argument for the situation that its called in.
It can be
mwqotDefinition,mwqotQuery,mwqotExecute,mwqotResolve,mwqotMoreData,mwqotMetaData
The reason its being called multiple times when opening the query, is that the dataset first likes to get the definition (which fields and parameters will this query result in), and then the data itself.
Both the server and the client default operates like that. Hence opening a query on the client result the client in asking the server about definitions, then the client asks for the data, and that on the server may result in the server itself asking for definitions and then the data. Remember the server is stateless and default doesnt know anything about previous calls to it.
There are many ways to optimize this:
Enable caching for metadata (definitions). That will result in the cache results being used instead of the server asking the database for the definitions, and enabling the cache on the client too, results in the client not having to ask the server for definitions except first time.
Setup the AutoFieldDefs property on the query to mwafoWithData. Then the data will actually be returned at the same time as the definitions, and the 2.nd data fetch call will be skipped.
I have a ef 4 model and I'm using self tracking entities. In this model there is an entity called Organisation. Each Organisation can have many Locations (addresses). If I try to select a single location (so I can delete it), thus:
var location = _container.Locations.FirstOrDefault(l => l.Id == id);
I get an erorr that there is already a data reader open so I cant open another. If I do the following:
var location = _container.Locations.Include("Organisation").FirstOrDefault(l => l.Id == id);
Then it all works just fine.
Using Intellitrace I can see that with the failed query it executes an ADO command to get just the location then does another command to get the location and the organisation.
Is this a bug or something I need to do differently for selftracking entities?
No it is not a bug. This usually happens if you iterate result of one query and in this iteration you execute another query (it can also happen due to lazy loading but lazy loading is not supported with self tracked entities). The simplest solution is simply allowing multiple active data readers (your database must support it). In case of SQL Server 2005 and newer you can simply add to your connection string this part: MultipleActiveResultSets=true;