Telnet connection with SQL Server - c#

What is the simplest way to create a client application(in c++/c#) to communicate with the SQL Server?
Since Iam a new-bie and very eager to know how this Database server is managing its connections, requests and responses. I have tried TELNET with the following command assuming that, I can open the connection and write to it.
TELNET <server> <port>
But the command ends up with a black screen only.
Please provide your comments as well as any helpful links.
Playing with HTTP connections was fun, since there was web-browser inspectors(like firebug) to help me:), but here I think things are much difficult & different, (Or if such a tool exists to log TCP connections?)

TDS, the protocol used by SQL Server, is not similar to HTTP or SMTP in that the commands are not sent via text, making it not terribly amenable to usage over TELNET. There's not any easy equivalent to:
GET / HTTP/1.1
There's some documentation on TDS here (from Microsoft), here (from JTDS, a JDBC driver for Sybase and SQL Server), and here (from FreeTDS) if you want to dig into it. If you want to observe the raw packet data, just use some sort client as Jirka Hanika recommended and use Wireshark or another packet-capture tool to observe the data.
Ultimately, if you want to learn something about network protocols, then maybe this worth playing with, but if you want to learn about SQL Server and relational database internals, there are much better places to start than with the network transfer layer, which are incidental to the actual function of databases.

For C#, look here. For C++, look here.
Make sure that you are freeing the database connection after use.

Related

How determine if using SSL in a MySql Connection?

We are using v6.9.9 of the .Net MySql Connector to access MySql using this connection string, specifying that SSL is required.
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
SSL Mode=Required
Our DBA has turned on support for SSL, but during my testing, I am able to connect to the server regardless of whether I have certificates installed on my machine, and also regardless of whether I have "SSL Mode=Required" or not.
However, when my DBA disabled SSL, if I use the above connection string, I got an error that SSL was not enabled.
Therefore, I really just don't know if my network traffic is being encrypted or not. How can I verify?
--
My question is a bit of a duplicate to this one with no accepted answer.
How to check whether a MySQL connection is SSL encrypted?
Some recommend using WireShark to test. Does anyone have step-by-step instructions on how to use this tool to verify my SSL connections?
--
This link talks about calling "status" from the MySql client.
https://dba.stackexchange.com/questions/36776/how-can-i-verify-im-using-ssl-to-connect-to-mysql
I asked my DBA to try it - but he isn't able to call that method against my connection, only against his local connection. Is there anyway to call this, for example, within my c# code?
I tried this, but I don't think the returned values tell me if the connection is SSL or not.
SHOW SESSION STATUS LIKE '%Ssl%';
Anyone with detailed information on how to verify my SSL connections would be greatly appreciated! Thank you!
Didn't work a lot with databases, but network/wireshark expertise is enough for you task. So what should you do:
Prepare capture setup using this tutorial
Start sniffing network with wireshark and perform some queries to your database
Filter traffic by database IP-address and/or port using display filter, so irrelevant packets aren't shown
Examine displayed packets. Compare them to sample of MySQL over TCP and to sample of MySQL over SSL. Hint: you can see queries as a plain text in unprotected connection, while SSL makes packet payload look like bunch of random garbage.

Best way to sync remote SQL Server database with local SQL Server Compact database?

I realise this is a much discussed topic but all the suggestions I see seem to involve direct access to the SQL Server which in our instance is not ideal.
Our scenario is a remote SQL Server database with (say) 100 tables. We are developing a lightweight desktop application which will use an SQL Server Compact database and sync a subset of (say) 20 tables with the remote server periodically.
I would like to have control over how the replication occurs because speed is a major issue for us since the remote server is 1000's of miles away.
Also I don't need to sync all the records in each table - only those relevant to each user.
I quite like the SQL Merge facility however it requires that the client be connected to the remote SQL Server. This is currently not possible and we were thinking of interfacing to the remote server through a web service accessed through our application or some other method.
Any suggestions welcome.
UPDATE
Just to clarify, internet connection will be intermittent, that's the main reason why we need to sync the two databases.
The fact that you are using a compact db for the client puts some pretty heavy limitations on you for available options in this scenario.
Given the limitations and the performance requirements you desire, you could consider implementing a service-based http endpoint to keep the desired tables in sync. If your architecture allows for it, doing so asynchronously would boost performance significantly but again, it may not even be viable depending on your architecture.
Something else to consider is using web sockets rather than standard http connections for a web service like mentioned above. That way you could keep the clients synced real-time, since web sockets are true fully duplex real-time connections. The major catch with this is you would either have to ensure all clients are web-socket compliant or provide a fall-back to emulate a websocket connection with an emulation framework for clients that aren't up to par.
Not sure if this helps any.
You have the choice of both Sync Framework (requires more coding and has some other limitations) or Merge Replication, both work over http/https) - see this blog post for a comparision: http://blogs.msdn.com/b/sqlservercompact/archive/2009/11/09/merge-replication-vs-sync-services-for-compact.aspx
Can you not use the MS Sync framework?
Pretty much designed for your scenario AFAIK.
Quick google turned this tutorial up...
http://social.technet.microsoft.com/wiki/contents/articles/2190.tutorial-synchronizing-sql-server-and-sql-server-compact-sync-framework.aspx

Remote database connectivity in C#

I have a windows tablet application which store some data from the users. Now i need to send this data to a server via Internet. What all options are there for me to try?? I think syncng the server and client database wont do good since multiple tablets are getting connected to the server.
I think syncng the server and client database wont do good since multiple tablets are getting connected to the server.
Why do you think that? How do you think web servers work? Databases can easily handle multiple connections.
You can either directly connect to the db server, if it supports remote connections, or you can create a webservice and communicate with db via that. Either way, be sure to set the permissions right, otherwise you might have a serious security problem.
// edit to address concerns in the comments
If you want to use a direct connection, you connect to a database exactly the same way as if it was on the same machine. How do you connect to that CE db?? You just need to alter the connection string, but everything else stays the same.
If you want to use a webservice for parsing and communicating with the database, the things get a bit more complicated, but it's still fairly simple. Search the google (or SO) how to use a webservice and how to create one. There are plenty of examples and tutorials out there. It's impossible to cover it all in here I'm afraid.

Java android client communication with C# server

I am currently writing an application having a client server architecture.
The client is a Java android application
The server is a C# application.
The client will pull data from the server but in some cases push some data to the C# server as well.
The data that server needs to forward the clients is list of data structures (perhaps in the form of XML?), sometime binary data like files.
The client and server are communicating over a wireless network.
Speed and scalability is my top most priority in the design of the system,...
I have to write server as well as the client myself. I will be using sockets for communication.
I need your advise on the form of protocol I should use to exchange data between the Java client and C# server.
Should I write similar data structures (which seems redundant) in java and C# and serialize them ??
or should I exchange xml ??
I am not sure yet what is the best way to do it ..
Essentially there will be commands from client and server will respond with data
Please advise me on this topic the data communicated could be be as large as several gigs over wifi so speed is very important.
Well, there's always JSON. It should be well-supported on both ends and is easy for your server to generate and client to consume. Not sure it helps with your bandwidth concerns any...
I believe WCF might be approperiate for this, WCF uses soap so a Java implementation should work well. WCF also supports steaming, so transferring large files is possible, though I'm not sure if Java supports the streaming protocol.
As for performance, you will probably be limited by the speed of the device and not the protocol.
Have a look at this session from TechEd 2011: "My Customers Are Using iPhone/Android,But I'm a Microsoft Guy. Now What?"
http://channel9.msdn.com/Events/TechEd/NorthAmerica/2011/DPR304
It would probably be worth looking into MonoDroid if you want to share code between client and server (and if serialize/de-serialize makes sense).
As I don't know what you're building, I would advise you to read up on REST before you continue though. It should give you valuable pointers on how to create a nice API that can be easily consumed by various clients.

What's the best way for a C# Desktop client to connect to a remote MySQL Db?

I am just learning c#, and am programming a Windows client that collects temperature data from the computer and needs to send it to a remote linux mySQL Database.
I was going to program it directly in the c# client, but I want to learn more ways to do this and gain experience. And programming it directly would be less secure and most likely require an extra connector.
Can any of you advise me of other ways, or ways you would do this?
Any way to program a C# program that acts as a web-service on my linux mySQL Server? Where should I look/search to learn more about this. Is it called something special? Or maybe its not done in C#?
Should I program a php script that accepts HTTP SEND/GET requests from my C# Desktop client?
Any other way?
What way is most 'professional' in the real world? Trying to learn on my own! :D
FORMAT:
Windows Desktop: client programmed in C# That retrieves temp data and needs to send to server
Linux Server: Runs Apache and mySQL Server with a database already setup. Closed to outside Connections
My advice is to set up a web service to communicate with your windows client. Directly connecting to mysql server is ok if they both resident in a same lan, but if not, for example your windows client is running on some laptop travelling everywhere or even the mysql server permits local incoming connection only, your should set up a web service. Also the http connection can usually go through firewalls while connections over other ports are blocked.
php is a good way to do this. Since you are learning c#, you may want to use c# to do the server side programming as well, so why not give a try of mono?
Directly exposing a MySQL Server to the internet is strongly dicouraged, Additionally this gives you a rather coarse-grained set of access rights, that might not be enough for your application, so running some sort of server app is the right way to go.
With mono you can run a lot of .Net (and thus C#) based code on a Linux server just fine. Rule of thumb is: If it doesn't have a Winforms GUI and no P/Invoke it will work just fine. Ofcourse this needs mono on the server, which is not given on most commercial hosts.
Running the server in PHP makes it a lot more portable, but has a performance overhead. Additionally it doesn't allow for some of your busines logic objects to be implemented in a DLL assembly and used on both sides.
As for the protocol: Chose your poison. Rule of thumb again is, that predefined protocols such as SOAP tend to need a bit more work (and more learning in the first go), but on the long term tend to be more robust.
For your special use-case I'd personally go with a quick PHP based solution where the protocol is just a simple GET with a few parameters, one being the temperature(s) and the others authenticating the client.
If the temperature sensor generates events, then I would 'push' the data from the Windows box to the Linux box - this will save the latter checking often and finding no updates. However if you are just taking temperature samples, I would 'pull' the data from the Linux machine. Either way, if you want to use HTTP you will need a web service on either side.
Alternatively, you could just connect to your MySQL database remotely from C#, and write the data directly (no web service would then be required). That might be the quickest way to get this working.
The 'which is professional' question is subjective - all three options above are fine. Just make the code clear and concise :)

Categories

Resources