first hi all,
i got a db sqlite in my project also got xml files and i translate data from xml and save to local db,
string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string localFilename = "personel.xml";
string localPath = Path.Combine(documentsPath, localFilename);
this is my local db, im planing to move db3 to iss, when i move should i give
localpath like = 192.23.21.2/www/personel.xml?
or should i add more things like http://docs.xamarin.com/guides/cross-platform/application_fundamentals/web_services/ ?
and second question
what if multiple users update or delete from table?
there is a one db3 file and same time 3 connections how can i manage it?
SQLite is not designed to work as a multi-user database.
If you have many client programs accessing a common database over a
network, you should consider using a client/server database engine
instead of SQLite.
It is also a really bad idea to allow your mobile client app to talk directly to a remote database. This is why web services are usually recommended as an additional layer between your client and a central, remote database. They allow you to introduce an additional layer of control and security over your data access.
Related
Microsoft documentation indicates that an app using the code-first approach can simply specify the model, and the database will be created if it does not already exist.
But I want my app to store it's data in a database on the end-user's hard-disk. So I can refer to localdb (for SQL Server) in my connection string, but I still don't know what folder on the user's machine will have the database files.
How can a user back up her data files, if she doesn't know where they are?
Is there some way to ask the DbContext object where it's files are stored?
I know I can specify the path of the database when it is created via SQL, but I've been told that it is not good form to mix EF-style database interaction with non-EF database interaction (from ADO.NET).
From the Microsoft documentaion page:
User database files are stored where the user designates, typically
somewhere in the C:\Users\UserName\Documents\ folder.
So the person or setup program installing the SQL Express localdb knows where the database is.
EDIT:
To set the connection string at runtime, you can pass a connection string, instead of a connectionstring name, to your db context. You can create your connection string on your own or use a EntityConnectionStringBuilder.
// Manually build the connection string
var connectionString = "Server=(LocalDB)\MSSQLLocalDB; Integrated Security=true;AttachDbFileName=" + pathToDatabase;
var dbContext = new YourDBContext(connectionString);
I am a DBA and have decided as a project to help me learn c# / ef to build an app that monitors sql servers, the idea is to develop a windows service that runs to collect all the stats from various sql instances using scheduled jobs in .net quartz. i.e. connected users and details from various dynamic management views.
to store the configuration data i.e. what servers to monitor I am using an sql database so it just contains a table of servers to monitor you will be able to add move via a web ui.
now the issue I have is how to loop through the servers "table" in EF and obtain the connection strings column and use this to connect to the various sql instances to get stats. (these will later be written back to the database for analysis by a front end)
e.g.configuration table data:
servername: test server
connectionstring: testserver\inst1
hope that all makes sense, thanks for your time
You can create a list of all your connection string keys like this-
List<String> DataVaseKeys = new List<String>(); DataVaseKeys.Add("testserver\inst1");
DataVaseKeys.Add("testserver\inst2");
foreach (var key in DataVaseKeys) {
string currentConString=System.Configuration.ConfigurationManager.
ConnectionStrings[key].ConnectionString;
//access to the data base with your connection string here
}
I use mdf database file. In server side I keep mdf file in D drive. Now I share this mdf file via lan to client system. If Client add any data means, it want to save in this shared .mdf file. For this how can I Proceed this and what is the connection string for this. Please reply me as soon as possible.
Thank You
By adding "|DataDirectory|" to your DataSource, you can make the path relative to the execution directory, so the user doesn't have to put a new path inside the DataSource. As far as I know you can't access the data from your customer. You would have to synchronize your DB with your customers.
Saving your data programmatically isn't that hard. Just use "SqlConnection", "SqlCommand"'s etc.
SqlConnection
Currently I am using SQL Server CE for persisting my data for which I am providing with a .sdf and connection string mentioned in app.config pointing to this .sdf file.
Now I want to provide user with the flexibility to have the data stored in their own SQL Server database if present at there disposal.
Now I am facing the problem of how to change the connection string at runtime if user chooses to uses its own database ?
Or if restrict them to use my predefined .mdf file how to attach that in their SQL Server ?
My recommendation would be to have 2 connection strings in the configuration file (app or web). There is a special section for them intuitively called ConnectionStrings. You can then switch between them based on other settings.
Changing connection strings dynamically is actually pretty easy to do as long as you have a place to store the new settings (ie. web or app config files). If you provide a way for them to enter the server information you can use the ConfigurationManager class to update your app/web.config.
Ado.net typically has parameters on almost any db connection object that allows you to specify the connection string as an arguement. Additionally, there are helper classes that can be used to construct the connection string on the fly like the SqlConnectionStringBuilder or EntityConnectionStringBuilder. I personally love the Entity Framework as it allows you to create the database from the model itself if it does not already exist, provided you already have the connection string.
I have been working in a business writing advanced software apps, and obviously im provided with access to our SQL server and all the connection strings needed.This is fine for my job now - but what if i wanted to do this for a new (very small) business... If i wanted to purchase a small database server and set up a piece of software that talks to the databases on this server, how would i go about a) Talking and connecting to the server in code (c#) and b)What would i need regarding things like internet/phone connections etc to make this possible.
Edit: the reason it would need a server is because it would need to be accessed from 2 or 3 different computers in different locations?
Actually there are quite a few ways to create a database connection, but I would say one of the easiest ways is to utilize the methods and classes found in System.Data.SQLClient. A basic connection would look something like the following:
using System.Data.SQLClient;
namespace YourNamespace
{
public class DatabaseConnect
{
public DataType getData()
{
DataType dataObj = new DataType();
SqlConnection testConn = new SqlConnection("connection string here");
SqlCommand testCommand = new SqlCommand("select * from dataTable", testConn);
testConn.Open()
using (SqlDataReader reader = testCommand.ExecuteReader())
{
while (reader.Read())
{
//Get data from reader and set into DataType object
}
}
return dataObj;
}
}
}
Keep in mind, this is a very, very simple version of a connection for reading data, but it should give you an idea of what you need to do. Make sure to use a "using" or "try/catch" statement to ensure that the connection is closed and resources are freed after each use (whether it successfully gets data or not).
As for your other question about what equipment you may require. In the beginning I would suggest just creating the database on your local machine and running tests from there. Once you are confident with trading data back and forth, feel free to move the database to another box or an online server. Any internet connection type should suffice, though I can't vouch for dial-up, haven't used it in years.
One final note, if you do happen to decide to move to an online server system, make sure that the service you use allows for outside connections. Certain services use shared server systems, and force users to use their internal database interfaces to manage and write to the database.
--- EDIT ---
As for the server system itself, build up a separate box on your local network that you can see, and load up the database software of your choice. Since you are using C#, it would probably be easiest to go with Microsoft SQL Server 2005 / 2008. The installation is rather straightforward, and it will prompt you to automatically create your first database while installing.
After installation it will be up to you to add in the tables, stored procedures, custom functions, etc... Once your base structure is created, go ahead and use the above code to make some simple connections. Since you are familiar with the above practices then I'm sure you know that all you really need to do is target the server machine and database in the connection string to be on your way.
In case your application is small (by small I mean the usage of resources like CPU and memory) then your SQL Server can reside on the same box.
Else you need to have a separate server box for your database and connect to that from your application. In this case, preferably your database box and application box would be on the local area network.
Check this link for having a connection to SQL Server from C# code - http://www.codeproject.com/KB/database/sql_in_csharp.aspx
cheers
You should probably expose your database with an xml web services layer, so that your architecture will be scalable. The general idea is host your sql server and webservices, using Native SQL Server XML Web Services you can make this available to your remote clients. When in your clients you simply add a service reference in Visual Studio and your data will now be available in your client app.
Hope this helps some.
Cheers
You may find the connectionstrings website useful - worth bookmarking.