make a single PC application work on the network - c#

I have a working WPF application that uses EntityFramework 6.0 to connect to a SQL Server database. Below is how my source code is structured.
TestPacks.Data contains the model of the database and logic to interact with the database. While TestPacks.Entities contains the mapped entities.
Now, I need to make this Application work on the local network so that multiple users can see the same data simultanously.
Here is how I plan to go ahead.
a) install the database on a server machine
b) change the below connection string to reference the database from the server instead of the local machine.
<connectionStrings>
<add name="TestPacksContext" connectionString="metadata=res://*/TestPacksModel.csdl|res://*/TestPacksModel.ssdl|res://*/TestPacksModel.msl;provider=System.Data.SqlClient;provider connection string="data source=WASIM-DELL;initial catalog=TPM;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
Is there anything else I will require to do for my application to work correctly? My requirements says that about 10-25 people (max) might work on the application over the network.
Please suggest.

You need to do concurrency check, Refer this sites Entity Framework Update check if the record has changed "http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/handling-concurrency-with-the-entity-framework-in-an-asp-net-mvc-application"

Related

moving from local database to remote. What do I need?

I've got some desktop experience, but am (brand) new to web programming. I've built a well-received C# WPF desktop app that stores data in a local (on user's desktop) SqlLite DB. I'd like to transition the app to remote data storage, probably with a MS SQL Server DB, hosted by a web-host service provider. One database there would hold all the various users data, access controlled by their own username/password.
In fact I've already done that as an experiment, and it functions. My concern is security: at the moment my in-code connection string just uses my db account/password. I'm not such a newb to know that's not a good idea. There must be a standard way to move that private information out of the code and into a sort of relay between the app code and the db. But I don't know the terminology, or what to ask for, despite a day of googling. So:
(1) User requests data save, say
(2) App sends SQL statement and user credentials to relay.
(3) Relay checks credentials against db records (using my db credentials, but that's ok, they're at least not stored in the apps's source code)
(4) Assuming ok, forward sql statement to db.
Is (something like) this a thing? What's it called? Or is there some other standard way to achieve the goal of keep my connection string completely out of the code? Where do I begin reading about how to implement it? How would I know if my web-host would support such a thing?
From the point of view of web-app operations, your connection string, from your dotnet app to your RDBMS server, is considered a secret. That means it's data you retrieve from a configuration file, and is never checked in to your git or other source control system. That connection string contains your RDBMS username and password, along with stuff like the name of your database and the server where it runs.
(If you did check in an RDBMS connection string to source control for any machine other than localhost, change that password. Do it now. Cybercreeps troll github looking for connection strings to steal and use for nefarious purposes. )
Dotnet web apps have a configuration file. It's an XML file called web.config. Connection strings go into that file in an XML stanza looking like this
<configuration>
<connectionStrings>
<add name="Name"
providerName="System.Data.ProviderName"
<!-- When deploying to production,
replace this connection string with one
to connect the production data base. -->
connectionString="Valid Connection String;" />
</connectionStrings>
</configuration>
Here's some info about retrieving that kind of connection string from your dotnet program..
I've had good luck putting a globally useless locally useful localhost connection string in that file, with some xml comments explaining that it needs to be edited when putting the web app on a public server. My example shows such comments.
It's also possible to edit a connection string with the web server's IIS Manager app. This setup -- either web.config or IIS Manager -- has good security.
The scheme you outlined is more complex than you need unless, heaven forbid, every one of your customers has a different connection string.

Weird SQL Connection Issue

I've got two applications, one is a pretty standard ASP.NET MVC C# 4.5 and the other is a standard C# 4.5 Windows Application.
They both connect to the same SQL Server using exactly the same connection string, and the web application connects successfully.
However, the Windows Application fails with the following:
A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The specified data could not be decrypted.\r\n)"
This occurs locally, on the test server and the live server but I have absolutely no idea why.
All it's doing using a simple SqlConnection object and calling the Open() method.
I've got another client with the same mix of Web App and Windows App projects and there are no issues like this at all, yet if I copy one of the Windows Apps from the working client and incorporate it into this one, it fails.
I am literally clueless with this one and I think I'm about to cry, so please, if you can offer any insight at all, please do...it's probably something really simple that I'm missing.
2 connection string settings in app.config that I've tried:
<add name="XXXXXX"
connectionString="Data Source=.\SQL2014;Initial Catalog=****;User ID=****;Password=****;Persist Security Info=True;MultipleActiveResultSets=True;enlist=false"
providerName="System.Data.SqlClient" />
<add name="XXXXXX"
connectionString="Server=.\SQL2014;Database=****;User ID=****;Password=****;Encrypt=True;TrustServerCertificate=True;Connection Timeout=30;MultipleActiveResultSets=true" />
Can't connect to SQL Server database from Local IIS over HTTPS
I think this is due to a component called NCrypt (available via NuGet) which I've isolated to be the cause.
When it's in my bin folder the executable fails to connect to SQL, and when I delete it the connection succeeds like I would expect.
The chances of anyone else giving me the answer to this were minimal at best, so I'm sorry to have wasted your time...
At least I've worked it out!
Try adding Integrated Security=true; to your web config. You can also specify Trusted_Connection=True; or Integrated Security=SSPI; All of these mean the same. I suspect your Windows Authentication is not trusted on the desktop.

Connecting to SQL Server Database using a Hosted Web Application

I have created a .net web application using c# that inserts, updates, and deletes data from an SQL server database. I have tested it using my localhost and it works fine. Now I would like to publish this application on a hosted site.
My question is, does the database need to be on the same server/host that the application is in for it to connect?
Does anyone have any tips on how to implement this?
No you do not have to run the Database on the same server as the application. For scalability it can be best practice to separate the two, one dedicated server for your DB and one server to host all your websites.
In your application you specify the connection to your Database. On your Database server you can also then set restrictions on the IP to access this data if you really wanted for further security.
If your Question is 'How to connect database present on another server', then you have to Add IP address of it in the Web.config file as:
<connectionStrings>
<add name="myConnectionString" connectionString="data source=myserver\SQLEXPRESS;initial catalog=myDatabase;uid=myUserName;password=myPassword;" />
</connectionStrings>
data source can be IP ADDRESS or PC NAME, where Database is stored.
does the database need to be on the same server/host that the application is in for it to connect?
It's upto you to put the Database on the same machine or a different machine.You can choose following scenarios
If it's a simple website and you only have one Machine,then you can install Database on the same server(or if'ts already present) .In this case the connection string may or may not have to change depending on what type of connection string you use(e.g if your sql server instance name is different,connection string will change)
Your website can get complex or process large amount of data,it makes sense to use a dedicated database server .This case connection string will change
Does anyone have any tips on how to implement this?
Easiest way to deal with this is using web.config transformation.All you have to do is create a new Web.Release.Config
Please refer this answer for more details How do I use Web.Config transform on my connection strings?

How can I run C# app which contains local SQL Server database on another computer?

I have created a C# program with a SQL Server database. It works fine on my computer but on my friend's PC it doesn't (my friend doesn't have SQL Sever 2008). Is it possible to make it without any installation? And if it can, how can it be done?
This is my connection string:
connectionString="Data Source=\v11.0;AttachDbFilename=|DataDirectory|\MainDatabase.mdf;Integrated Security=True"
SQL Server is for server databases. You can change your project to use SQL Server CE (SQL Server Compact Edition) which is a single-file local database. It is very similar to the "true" SQL Server so it may be the easiest solution. Your code probably wont change except for the connection string.
Use the IP address of your local machine in which the database is present;
1433 is the default port number. Then modify the connection string accordingly:
connectionString="Data Source=190.190.200.100,1433;
Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;"
First time you open port 1433 in firewall if you don't need you can turn off firewall.
go to Run=>cmd=>Ipconfig find network's card activity. Show like
Like my computer have just wireless and my andress in private lan is:192.168.100.165
And now you change connectstring in web.config.
connectionString="Data Source=192.168.100.165;
Initial Catalog=yourDataBase;User ID=yourUsername;Password=yourPassword;"
If you don't know "yourUsername" and "yourpassword" please refer link
and create username and password in MsSQL
https://msdn.microsoft.com/en-us/library/aa337562.aspx
And if you want to connect database from internet you need to do open port your's router
If you want to run your program without the SQL server installed you have to use a service based sql database.see this image
you can add a local database through Visual Studio (project--> Add new item)
My solution will cater if you need a SQL database on your friend's computer instead of hosting from your own.
The cheapest way to handle a database locally on any device using a proper database is to convert to SQLite. This is a local device alternative that is more lightweight and doesn't require any user to install a SQL server at all.
There are also alternatives like writing information to a hidden file (usually in binary if you don't want your application to be hacked).
In short, only consider a SQL database IF you are hosting the database, otherwise use alternatives.
As far as I know, you have one of 2 options. You either have a server (a pc set up to be a server and containing this database) or you could take the easier option and host your database on the cloud. Many websites offer a free service to host your database for a limited amount of time, or limited storage. If you have Azure subscription that would definitely be the way to go.
If your connection string is like below
connectionString="Data Source=\v11.0;AttachDbFilename=|DataDirectory|\MainDatabase.mdf;Integrated Security=True"
then you should install sql localdb 2012.msi on your friend's PC.
And make sure the .mdf file is located the same as on your computer.

Connection string for a SQL Server database sitting on a local drive

I'm trying to test an application and I need some friends to test it for me who live elsewhere. I've got VS2010 installed on a WinXP machine and I have SQL Server 2008 R2 installed on the same computer. Both applications are installed on the C:\ drive of the WinXP computer.
I gave my IP address to my friends. They can see the website, however they can't access any of the data.
Is there some standard connection string I would have to access this data, or is this one of those "I have to sit in front of your computer to know what's wrong"-type things? The connection string I currently have in my web.config is:
<add name="MySiteConn"
connectionString="Data Source=localhost;Initial Catalog=TestDB;Integrated Security=True"
providerName="System.Data.SqlClient"/>
If you have access via VS but not via the website, its probably because your (I assume) IIS account doesn't have access to the database. You are using integrated security.
It might be easier to add a user and password to the connection string, then give that user access to your DB and tables etc. I would just use the IIS user, but there are probably best practices in this case you can follow. Since you are hosting it all on XP I assume security isnt your top priority.
If the connection isn't the problem (if you have VPN set up or whatever means of connection), then it might be your SQL Server is not configured to get connection from other computers. Make sure you allow other connection to SQL Server, check SQL Configuration Manager and configure Firewall Inbound Rules. Otherwise I'd go to Elizabeth's answer.

Categories

Resources