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
Related
I need to import xml file into Microsoft SQL Server database. And I have a xml schema file (.xsd) that contains the mapping info for the xml file to be imported. Each valid data line in xml file need to be imported into a database table row with several columns.
Originally I was using SQLXMLBulkLoad (Non Transaction Mode - specify a database connection string) to do the job and it works just fine, however, there is a new requirement that need me to execute a stored procedure on the same database connection that SQLXMLBulkLoad uses. The purpose of this stored procedure is to bind the connection with a specific ID for the current user because there might be multiple users importing xml file at the same time. So I have to use transaction mode instead (- specify a database connection rather than a connection string for SQLXMLBulkLoad) and which introduce the well known share issue under remote environment. If the xml file is local and the db server is remote, I need to create a shared folder for SQLXMLBulkLoad to work. This is bad but can be done.
The problem is the share folder thing is not accepted by our clients, so I need a better solution that could satisfy the new requirement without the share issue.
I've Googled a while and found one solution that might work - SqlBulkCopy, but I have trouble with parsing the schema file (.xsd) because it contains many xml-db:table mapping information.
Any idea would be appreciated.
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.
I have found several posts about how to perform a database backup and database restore using the Sql SMO assemblies in C#. Basically if I want to make a copy of a database and give it a new name, I need to provide Relocate Files when doing the Restore. The Relocate Files consist of a Data File path and Log File path. If I'm restoring from an existing database then I can simply inspect the Database object's FileGroups property to get the Data File path, and it's LogFiles property to get the Log File path, then modify the path's filename to use the new database name, and provide these when doing the Restore. Without providing the Relocate Files the Restore operation would just overwrite the original database (overwrite it's .mdf (data) and .ldf (log) files).
So I have all that working fine, but now I've run into the case where I want to create a new database from a database backup file (.bak) that the user supplies, and they should be able to specify a new name for the database. In order to give the database a new name and not overwrite the existing database files (if they exist already), I need to know the backup file's Data and Log File paths.
Are there SMO functions that I can use to inspect a database backup file for it's database name, Data File path, and Log File path? I'm assuming there are, since SQL Management Studio is able to do it, but looking through the MSDN documentation I haven't come across it yet.
Thanks in advance.
== ANSWER ==
As linked to in Ben Thul's answer, the answer is to use the ReadFileList function on the Restore object. Here is some sample code:
Restore restore = new Restore();
restore.Devices.AddDevice(Path.GetFullPath(backupFileToRestoreFrom), DeviceType.File);
DataTable fileList = restore.ReadFileList(server);
string dataLogicalName = fileList.Rows[0][0].ToString();
string dataPhysicalName = fileList.Rows[0][1].ToString();
string logLogicalName = fileList.Rows[1][0].ToString();
string logPhysicalName = fileList.Rows[1][1].ToString();
Check this out: how to restore using restore class of Microsoft.SqlServer.Management.Smo namespace. In T-SQL, you'd accomplish this with restore filelistonly from disk='path_to_your_backup'
I am using VS2010 , and I built a .mdf file using SQL server 2008
I want to use this database file in my wpf application so that I can add rows to it and delete rows from it
the problem is , I can't access this file , and all the insertion and deleting is actually hapening to the datacontexct i created .
I used myDataContexct.Submitchanges() but it didn't work either
I tried to add a connection string when I define the datacontexct that holds the url of my .mdf file and this it gave me a runtime error when trying to access this file and the error messege says :
An attempt to attach an auto-named database for file Trial.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
please help me because I searched alot but I couldn't find any help
If the application is not going to be installed in a manner that many clients are accessing the same server, you would want to consider using SQL Server Compact Edition.
Are you sure the connection string in your app.config refers to the local mdf file? perhaps it refers to the server instance?
What technology do you use, is it LinqToSql or Entity Framework (I think you have t call SaveChanges, not AcceptChanges)?
If you do intend to access the server instance, then the problem seems to be a security restriction.
Please add more details on statement no. 1, and I'll write further info.
I am developing a desktop application in c# & sql 2005. With candidate data entry form I want to provide option to attach required documents(in pdf format) wid data. Kindly let me know the best method. Thank you in advance.
Simply create a table that will contain the filename and server path for the file to be attached, then create a method to copy the attached file to the server location and store the relivant information (name and path) in the table. Use other methods to retrive the file from the server location when requested. Simple.
I personaly prefer to store the documents as BLOBs since server file structures and paths can change over time.
Well then unfortunately you have to either manage the file storage yourself using the servers file system, or you could store it in the db itself (IT WILL GET BLOATED!!!)
See sql server 2005 file storage
How To: Encrypt and Manage Documents with SQL Server 2005
OK, then for file management
see this example
File Manager Component