here is the problem I am facing now. I have created an application that uses local database (this was created by Add -> New Item -> Local Database. Afterwards I have added tables under this .sdf database.
Then I have connected to this database using Add -> New Item -> ADO.NET Entity Data Model.
Everything works like a charm, unless I was asked to move this database to a place, where multiple people could access this database and work with it.
Therefore, as I have no previous experience with databases, I have treated this .sdf file as any other file (let's say Excel workbook) and I thought that I could simply take already existing database, copy it on server computer (e.g. \Server001\Database\Database1.sdf) and simply change connection string under app.config.
However the problem is that this does not work. As I didn't know how to change connection string, I created new application, where I have tried to connect to this database located on a server computer; however I received the following error:
SQL Server Compact does not support opening database files on a network share.
I already have fully functioning program, but I have no idea how to make it work with multiple users. I have tied to google for solution, but all I could find is how to create local database, not how to make it accessible by placing it in server computer.
Could you guys please help me? If you need more details, please let me know!
P.S. This is WPF application, .NET 4.5, created using Visual Studio 2012 Professional.
Thank you!
The error message pretty much sums up the problem: SQL Server Compact does not support opening database files on a network share.
SQL Server Compact (aka "local database") is to be consumed by a local application; even if it was a web app serving many requests, the application itself is local.
If you want to have multiple remote connections (i.e. centralized DB, distributed app), you should look at using an instance of SQL Server (any SKU would probably work, even SQL Server Express). Those will use MDF files instead of SDF files, so you might want to refer to Convert .sdf database to .mdf database. You'll probably also need to set up a user identity for your connection string, so check out this link on CREATE USER and Difference between a User and a Login in SQL Server to understand how that can be configured.
Related
In my application I need to use a local database (the application I'm creating works with everything locally). I had one database that worked really bad, because sometimes it saved the data and other times don't. And if I published the program I couldn't find the database file.
But I am having some trouble to know where to place the database. I have created one in E:\PAP\Trabalhos\Trabalhos\database.mdf and other in E:\PAP\Trabalhos\Trabalhos\bin\Debug\database.mdf, but in any of those paths the database is recreated/goes back to the previous state, when I try to start the program.
In my connection string I have this:
Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|database.mdf; Integrated Security=True
and that points to the file ...\bin\debug\database.mdf
I want to be able to access the database in any computer I use the program and be able to actually save data.
Where is the recommended path to place the database file and be able to access it independent of the computer I am using?
Should I use Windows authentication or SQL Server authentication?
tl/dr: Database doesn't save data and I want to be able to access it in any computer without any extra steps.
You can't use "(LocalDB)\" and access it from any computer. LocalDB is by design accessible only from the applications running on the same computer (it is an embedded database).
To access database over the network you need to install instance of SQL Server, like full SQL Server Express instance or use some cloud service like AWS or Azure.
I have made a Wpf application and i am using linq to SQL classes also i have made my database in SQL server 2012 so is there any way that i can deploy my application in such a way that it will run on other PC's?
Check your app.config file. Make sure your connection string contains:
valid DataBase address
Valid credential for the db
As your update:
whenever i make setup file and run on another pc it give me exception
because sql server isnt installed on that pc
Either you need to deploy a database in internet, accessable by your app. Or you have to use an embedded sql db (e.g. add a db.mdf to your solution). I think this suit you better.
Am begging to the programming lords, I bit off more than I could chew and need some help. I have tried searching but I don't understand how to apply the solutions to my own.
I have written an application in c# for which I created a database called "Timesheet DB" within Visual Studio 2010 (there is a .mdf file with the application files, and there is a copy in the bin\debug folder which 'writes if newer' when I debug my app).
I added the tables and views to the "Timesheet Db" Data Connection in the Database Explorer window and dragged them into the designer view of "data_ProjectData.dbml" in my Solution Explorer. My app queries the Data Classes using Linq to Sql.
The "Timsheet DB" is an exact "replica" of a database my business has on our server computer which is using SQL Server 2008 r2 (is this the same as SQL Server Express which I've read about?)
I've been programming this on a computer that is not connected to the network, using dummy figures.
Now I'm stuck.
How do I get my application to read and write from/to the server version of the database instead of the one I have created in Visual Studio on my PC, then deploy it to my server computer?
I want various users on their own PCs connected to the network to be able to read and write to the Db (it is a timesheet application where users submit their times and managers can review and approve), I thought if it would work if they access a ClickOnce application from the server computer (they all have access).
I may make changes to the application from time to time (without the structure of the db ever changing), so I'm worried about not being able to deploy enhancements without messing up their existing data.
My first time delving into SQL server db application - it works beautifully in debug, but if someone can please help me get it working for my business it would be much appreciated!
Cheers
Steve
You have to just point the connection string to the server database and it is the only change required.
<add name="ApplicationDB" connectionString="Data Source=serverName\sqlexpress;Initial Catalog=TimeSheetDB;User ID=sa;Password=passw0rd;" providerName="System.Data.SqlClient"/>
This change has to be done in the App.Config for Windows Forms / Console Apps and in the Web.Config for the Web Appliacations.
Please do port the neccessary changes in your machine to the database server. When you have dragged and dropped the necessary tables on to the DBML designer window, this kind of connectionstring will be added to your <connectionStrings> section in the config file.
For ex. if your db is named as TimeSheetDB the connectionstring name will be as TimeSheetDBConnectionString
I am developing C# windows application first time.
Que 1 - ) I have developed my windows application which uses SQL server 2008 using below connection string..
Data Source=myMachineName;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
But When I created setup of my application and installed it to another computer then it is throwing error of could not establish connection with SQL server..
I guess this error is because of my connection string as it is specific to my computer and installing it to another computer will not work..
Hence How can I make my connection string which will work with any computer..
Que 2 - Do I need to attach schema file with my setup as How my database will be created into the other computers??
This might be silly qustion but as I am doing this first time , i dont know about this all.
Regards,
Mahesh
You should place your web config in app.config file which is in xml format.
And read it from your code.You can easily change app.config file through notepad according to machine.
Yes must have your schema script in setup if you want to create it from setup.Otherwise you create database manual on client machine.
If you've used SQL Server on your development machine, it has to be installed on every computer that will be using your app. There are several options to resolve this issue:
If your app doesn't need access to a central sql server (for example your app just keeps track of users DVDs), use SQL Server Compact Edition instead and embed it to your app
If your app needs some kind of a centralized data, get a dedicated SQL server first, install there everything you need and in your app change your current myServerAddress to the address of the server. Note that the server needs to be accessible from remote locations (some restrict access to localhost!).
Que 2 - Do I need to attach schema file with my setup as How my
database will be created into the other computers??
Again, multiple options. For instance, you can export your database to a .sql file (Right click on the db in your DB explorer and select option Publish to provider) and then import it using a sql manager on other computers. Or maybe you can create a .cs installation script, that will do the same job using C# code.
Edit based on OP's comments:
Example links for solutions:
question1: Embedding SQLServer CE in an installer
question2: http://support.microsoft.com/kb/307283
Okay that's fine but will my current Connection string work in that case as the DataSource
is my specific machine name
Of course not, you'd have to change it to point to the SQL Server CE database file. Probably the best way is to not hardcode it, but use a relative path to the database. It looks like this for instance:
Data Source=|DataDirectory|\MyDb.sdf, where |DataDirectory| points to the App_Data folder of your application.
Also plese see the error screen map i have attach with the question..
Your error is quite clear - there was a problem establishing a connection to your database. It either doesn't exist or isn't accessible from your current machine.
I have seen this question asked previously but can not find a clear explanation of what is/isn't possible and what workarounds migth be available.
I have an existing C# application that uses SQL CE to store local information. This database is only accessed by a single application and is stored in the user's appdata folder.
Some environments have the appdata folder redirected to a network share which causes SQL CE to throw an exception: "Internal error: Cannot open the shared memory region."
I have read that SQL CE 3.5 SP2 is supposed to allow connections to network shares again, and that SP1 does not, however I have not been able to get it to work. Has anybody had any success getting any version of SQL CE to work over a network share? And if so, what version/code did you use to get it to work?
I have tried using mode=Exclusive in the connection string with no luck.
Or alternatively, has anybody found a different workaround? The data needs to be stored in the user's profile as it is specific per user and should not be accessible by any other user on the system.
I updated the application to use SQL Express with local user instances which worked, but it created too many deployment issues for our customers. I ended up having to write a layer to use Access MDBs while we look at different database options.
My suggestion for writing desktop applications is DO NOT use SQL express or SQL CE for local storage.
I've used SQL CE 3.5 successfully on a networked drive with instances of an application running simultaneously on two networked computers. I was able to update records in the database from both locations.
I'm not sure what would happen if two users accessed the same record at the same time, however this is unlikely in my situation. Just include the database location in the connection string.
Store the data in a folder that is not redirected.
SQL Compact is a single-user, in-process database engine.
Have you tried to put sqlce DB on a shared folder and set its datasource where it is located?
Something like:
"Data Source=\\MySharedfolder\\DB.sdf;Persist Security Info=False;"