I want to create a windows application in C# and SQL Server, these have two databases one is in local another one in remote. I have 2 doubts:
Is possible to connect remote SQL Server in windows application?
Some time Internet may be not available (may be chance). This time I cannot fetch and store data in remote server, my application not running that time,how can avoid this situation?
Full data available remote server, partial database only in local SQL Server
please share ideas to me.
is possible to connect remote sql server in windows application?
Yes. Provided if remote connection in SQL Server is enabled. See How to enable remote connections in SQL
Some time Internet may be not available (may be chance).This time I
cannot fetch and store data in remote server , my application not
running that time,how can avoid this situation?
Check for connection to your server or catch exception to see if server is unavailable. Write the data on your local server or local XML file and then implement sync logic when ever your server becomes available
Related
I am developing a C# Windows Forms app for event management. There will be 15 gates with RFID readers. These readers will read the UID and query the database to check if it is unique entry for that day.
Now if for some reason, SQL Server is not available, I want the app to store the data in a local database and sync as soon as the connectivity is restored.
Any idea on how should I do it?
Thanks
You could use SQL Server replication, and install SQL Server Express with a local copy of the database on each device.
We have a requirement (I believe as part of a post build/deployment verification test (BVT)) to test that remote server A can "connect" to remote server B.
I want to develop a console application using C# on my LOCAL developer VM. This should then "connect" to remote server A. It then needs to check that remote server A can "connect" to remote server B (via the original connection from LOCAL to remote server A).
Currently I have generated a simple "helper" exe that connects to remote server B (using a prior known connection string point to remote server B and SqlConnection classes). The exe is copied to remote server A as part of the build process (at the end). PSEXEC.exe on the build server then remotely starts the "helper" exe on remote server A and checks the %errorcode%. This then determines if the BVT should pass or fail (Then the "helper" exe is then deleted from remote server A).
FYI all machines run Windows Server 2008 R2 x64 Enterprise and are on the same local domain. I am an administrator on all 3 machines.
Remote server A is a web server and remote server B is a SQL database server. The LOCAL machine will/does represent the build server. This test is simple as saying "can the web server connect to the database server". The difficulty is how to do that remotely.
I know I can just do System/integration/end-to-end testing (using Coded UI etc) and we are doing this but want to consider this requirement/test as well (as the servers and network configuration etc are a "shared responsibility" with an external party and we cant guarantee that anything has/will change without our knowledge (other than reacting via Service Desk processes))
The process I have adopted seems OTT but does appear to work (if I close ports etc). Is there a completely .NET way of doing it using TCPCLient classess or something etc? What about doing webservices and hosting them on the webserver and call them from the build server? Other ideas and things to consider more than welcome.
Why not create a test page on the web server that carries out an innocuous operation against the SQL server.
The page might execute a simple query (select top(1) name from person) for example.
I can see web-services tagged in your question. If you want to verify connectivity to a server hosting web services or between a server hosting web services and an underlying back-end server (database for example), the best way to be sure (in my opinion) would be to call an innocuous service that does a simple read. Retrieving WSDLs would not be enough.
You can use Management objects to query and control computers and servers on your domain.
http://msdn.microsoft.com/en-us/library/system.management.aspx
SQL server includes some extra objects specific to managing SQL Server.
http://msdn.microsoft.com/en-us/library/ms220749.aspx
If you have Linqpad:
ManagedComputer mc = new ManagedComputer( "yourserver" );
mc.Dump();
otherwise create a console app and create an instance of ManagedComputer and use the debugger to query the computer's SQL server, to see the sort of information available.
As you can see its a big subject...
I am pretty new to SQL and I'm stuck on something which is probably a few clicks away.
The program I am building will store the data in the database created on the management studio. Everything works fine on a test application. Now the question is: how should I connect to the database if I want to open the program from another computer? I tried copying the test project on a friend's computer but it cannot find the database as I suppose is obvious because the db is stored on my pc.
i know hundreds of questions like this exist around google but I'm sick of looking at forums reading complicated stuff. any help will be really appreciated.
thanks.
In the database connection settings or script you propably have database server set to 'localhost'
Try setting this to the computer network IP if the other computer is inside the same network.
To connect to it from outside the network (over the internet) You need set the database server setting to you external IP and you have to port-forward (NAT) the SQL server port to your computer.
If you can tell us what database software you are using for the Database I can tell you what port to forward, for more help with forwarding you should ask on serverfault.com and also provide your router/firwall make and model
It depends (at least partly) on how you're connecting to the database in the first place. Normally, you'll have some sort of connection string that tells what computer to connect to. It'll be set to the local computer by default, but changing it to something else is normally just a matter of editing that machine name into the string.
If you're connecting via ODBC, the program will just specify an ODBC connection, and the ODBC connection will specify the machine to connect to. You can use the "Data Sources (ODBC)" control panel to edit these (depending on the version of Windows you're using, it may be in the "Administrative Tools" folder instead of showing up directly in the control panel).
when you want to connect to a sql server over the network there are a few things you should know/check:
is your connection string correct (not localhost)
does the remote sql server accept tcp/ip connections
does the firewall of the remote compture allow the connection
Is the sqlbrowser running on the remote computer (if not you need to specify the port in your connection string.
To make sure this al works the best thing you can do is try to connect from the new pc to the remote database using sql management studio or if you don't want to install the ssms you can try to create an odbc profile that connects to the remote pc. By doing this you can determine if the problem is with the database itself or with your application.
I want to do system to control other machines in LAN. I need here a database, but it should be one database for all computers. I hope it's possible to have installed SQL Server only on chosen machine and connect from others to him over LAN?
Or make db on each comp and synchronise fom time to time with main db?
YES OF COURSE!!
That's the whole point of a database server....
You install a SQL Server version on your server machine, and any number of clients in your LAN can connect to it, read data from it, store data on it.....
Since you're in a LAN environment (inside a company), I would recommend using Windows authentication (the user names people are logged into Windows with) as your security mechanism. You can easily configure certain Windows users (or Windows groups) to have access to your SQL Server (and others are locked out).
Once you have set up your database server, your client apps can connect to it using a connection string something like this:
server=(server-name);database=(your database name);integrated Security=SSPI;
i have some questions about databases and remote connections..
i've made an application that connects to sql server db on local machine then i published the app. and installed it on other machine..
was very bad when i realised that the application won't work except that there are sql server instance on that machine.. :/
am thinking now to use access db instead of Sql Server..
but i don't know if i had to install access on every machine to make the app. work ?? or just the access db file "mdb" is enough to connect and react with data on that db ??
and if i had to install access on the pc that hold the database, do i had to install it on client mashines too in order to access the db on server with remote connection ??
answering these question will rly help me too much.
thx in advance.
No you don't have to install Access. ADO.Net will take care of connection.
Also you can use SQL Server Compact Edition. With adding some Dlls to your project, you don't need sql server installed on client machine as well.