hallo,
How can i transfer the table Command via WCF ?
i have a idee:
in client side :
using normal SQL syntax: SELECT * FROM COMMAND then wrap it the result into List or IeNumerable or another type of collection and then use WCF List GetCommand ()
and in server side :
call WCF List GetCommand () then loop the collection use INSERT INTO COMMAND...into table Command
is that a good idea ? if not could you give me a hints ?
Thanx you in advance,
Stev
PS: i just want to transfer specific data:
SELECT * FROM COMMAND WHERE REGION_CLIENT = 345 (not all database)
If what you are tring to do is to transfer data from a local client database to the server, you should use the microsoft sync framework, see: http://msdn.microsoft.com/en-us/sync/bb736753
Related
I am using Thingworx Platform for IoT. I have connected Thingworx and SQL. I have created 2 database SQL services of the type query and command. Also I have created two tables named Temperature and Humidity.
I am getting Temperature and Humidity values in Thingworx platform. But I am unable to send it to the database, can anyone help? How can I call the properties in the command service?
Database.Conf sql Command code
insert into INFO(Temperature)
values ([[]]);
Thing-Test Subscription Code
var params={Temp:me.Temp_Prop,Hum:me.Hum_Prop};
var result=Things["DatabaseConf"].InsertRecords(params);
When you create a service in ThingWorx you can select the type: "query" is a valid option when you have to insert or retrieve values from a database. You can test the query on SQl and copy/paste into the service.
Check if the thing that connects you to the DataBase has the property "isConnected" equal to True.
Maybe you should also think about how to trigger the Insert service, you can use ValueChange triggers or a Periodic Trigger.
You need an additionnal service of type javascript where you can retrieve the properties, using me.property and invoke the sql services. You can add input parameters to the sql services and use them like this: [[inputParameter]]. In your example that should look like:
insert into INFO(Temperature)
values ([[temp]],[[Hum]]);
If you use the arrow on the right of your input parameter, ThingWorx will write it for you in the proper way already.
Is there a way to identify what method in C# code is connecting and executing a query?
My thoughts so far is to generate a unique user for each connection in the application and then examine the SQL Server system tables to view the original_login_user.
I should note that I am using Azure SQL.
The OP is using Entity Framework, and you can log all SQL Queries that EF performs by doing something like
using (var context = new BlogContext())
{
context.Database.Log = Console.Write;
// your code here...
}
See the following for more information: https://msdn.microsoft.com/en-us/library/dn469464(v=vs.113).aspx
My first step to learning SAP HANA was usage of odata services related to database tables and database views.
I created the XS Project, then a database table, fill it with content and then created the sql view and definded simple odata service topowners.xsodata.
The sql view was grouped and ordered.
If i call (in Eclispe or WebIDE) the sql view "display content" , the entries are correct ordered by defined attribute.
If is call the odata service in XS Service (in browser) the entries are NOT ordered by defined attribute. How do I solve the problem? Thank you
odata Service definition
service {
"DB_XS"."SUM_VIEW" as "TopOwners"
key ("owner_code")
create forbidden
update forbidden
delete forbidden;
}
sql view definition
CREATE VIEW "DB_XS"."SUM_VIEW" ( "owner_code",
"owner_count"
) AS select
owners."owner_code" ,
SUM("current_owner_cnt") as "owner_count"
from "DB_XS"."owners" owners
group by owners."owner_code"
order by "owner_count" desc
p WITH READ ONLY
You can solve the problem by adding a $orderby in your oData request:
http:// ... /topowners.xsodata/TopOwners?$orderby=owner_count
See here for example
I tried to call linq query from sliverlight application to web service which is 'ADD.NET Entity Data Model' with 'WCF Data Service'. The linq below is working (e.g.using pre-defined table & field names):
var query = from o in context.ORDER
where o.NUMBER == 1
select o;
((DataServiceQuery<ORDER>)query).BeginExecute(OnQueryComplete, query);
But I need dynamically assign different table and fields names to the linq query. Is there any way? Do I need to write a method in WCF to execute any sql command?
Thanks for any help.
You can use the Dynamic Linq samples to provide dynamic field names in where clauses - see: http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx
Further, you can do this in a type-safe way using PredicateBuilder - http://www.albahari.com/nutshell/predicatebuilder.aspx
For more dynamic behavior - including dynamic table names - the only Linq option I can think of is to compile some code at runtime within your app using the CSharpCodeProvider (http://support.microsoft.com/kb/304655). However, obviously you need to be careful with security when offering this from a web service.
I'm using ms sql 2008 and trying to create a database name that references another database. For example 'Dev', 'Test', 'Demo' would be database names that i could reference from my multiple config files, but each name would point to another database such as 'db20080101' or 'db20080114'.
[Edit]Some of the configs are for applications that i control the code and some aren't (ex. MS Reporting service datasource file configs)[/Edit]
It seems that sqlserver only supports synonyms for View,Table,Sproc, or Function. And Alias' are for table and column names.
Is there a way to do this that i missed in the docs?
Any one have any suggestions on a workaround?
use 3 part notation and alias up to the table, example
select * from tempdb.dbo.sysobjects a
join master.dbo.sysobjects b on a.id = b.id
There is a way to simulate this using a linked server. This assumes you have two SQL servers with the same set of databases one for development/test and one live.
Open SQL Server Management Studio on your development/test server
Right click Server Objects > Linked Servers
Select New Linked Server...
Select the General page
Specify alias name in Linked server field - this would normally be the name of your live server
Select SQL Native Client as the provider
Enter sql_server for Product Name
In Data Source specify the name of the development server
Add Security and Server Options to taste
Click OK
The above is for SQL Server 2005 but should be similar for 2008
Once you've done that you can write SQL like this:
SELECT * FROM liveservername.databasename.dbo.tablename
Now when your scripts are run on the development server with the linked server back to itself they will work correctly pulling data from the development server and when the exact same scripts are run on the live server they will work normally.
I've done something similar to this using another config file.
The new config file maps your generic name to all of the information needed to connect to that database (db name, user name, password, etc.) and then your connection function takes your generic name as an argument.
db.config:
DEV_DB_NAME = db20080101
DEV_DB_USER = dev_user
DEV_DB_PASS = dev_pass
TEST_DB_NAME = db20070101
TEST_DB_USER = test_user
TEST_DB_PASS = test_pass
connection code:
db_connection get_connection(string prefix) {
db_connection db_conn = new db_connection;
string db_name = get_config_value(config_path, prefix + "_DB_NAME");
string db_user = get_config_value(config_path, prefix + "_DB_USER");
string db_pass = get_config_value(config_path, prefix + "_DB_PASS");
db_conn.connect(db_name, db_user, db_pass);
return db_conn;
}
Then you just call get_connection() with your db alias as the argument.
I know this probably will not help in all situations, but you still have the option of using views. You can insert, delete, update, select into a view as long as it has a proper identity key (Primary Key). If you point it to another database, you should drop and recreate to get the different schema (in case you're working between production and test while making changes to the schema in test and/or production.
Synonyms are useful for when you're going to another database and have a 3 or 4 part name, but when you want to make it so you can have a set name, a linked server will also work which will let you use a fixed name if the table names are the same in both databases and you're just pointing between prod and test.