Database connection fails - c#

I have written c# application that uses mdf file for database.when i make setup of that project and runs on other computer having dotnetframework and sql server compact 3.5 then id dose not runs and exception is shown saying something sql server not found or not ready for connection something like that what should i do

mdf is not for sql server compact edition, it is for the real sql server. You need to deploy it to Sql Server Express edition or higher.
Edit:
You can install SQL server express edition or if you want to use the sql compact server you need to create a "local database" in visual studio.
When adding a mdf-database to your visual studio project is is attached to your local sql express database server behind the scenes when you start your project.

Related

Understand localDB is relation to SQL Server Express and SQL Server CE

I'm trying to understanding LocalDB by reading MSDN: SQL Server 2016 Express LocalDB and MSDN: SQL Server Express LocalDB and SQL Server Express and a number of SO posts including confusion about SQL Server Express and localdb, I still cannot understand what is LocalDB. I understand and have used SQL Server Express and SQL Server CE.
Questions:
LocalDB...the necessary SQL Server infrastructure is automatically
created and started
My understanding is that, if using LocalDB to handle an application's database, neither the developer nor the client machine where the application is deployed needs to install the heavy SQL Server Express, but just need to install the lighter LocalDB. How, then, without SQL Server Express install can localDB "create(d) and start(ed)" SQL Server? If localDB
... once installed, LocalDB is an instance of SQL Server Express that can create and open SQL Server databases. The system database files for the database are stored in the users' local AppData path which is normally hidden.
If developer or client can use localDB without installing SQL Server, how can localDB be an instance of something that is not installed? Or is localDB an incomplete version of SQL Server Express that just does not need to click..click..click.. to configure. Essentially localDB works like SQL Server CE where localDB use some hidden "files" in AppData to create database while SQL Server CE use the dll to generate the database?
SqlLocalDB.msi program to install the necessary files on the computer
If client still needs to install localDB (which is not really portable along with the application like SQL Server CE), then why not just install SQL Server Express? Either localDB or SQL Server Express is above 100MB+ anyway and need separate installation, what is the point of using localDB anyway?
LocalDB is a programmer-oriented version of SQL Server Express that needs to be installed just like SQL Server Express.
Unlike SQL Server Express, it's not installed as a Windows Service that starts up with your Windows OS - but it only starts up as needed (when your application starts up, or when you start it manually with the SqlLocalDb command line tool).
But LocalDB IS SQL Server Express (not Compact Edition). It uses the same .mdf and .ldf database files like and desktop/server version of SQL Server, not SQL Server CE's .sdf file format.
We used localdb on a project where we had agents in the field using laptops.
The functionality of localdb was better than SQL Server CE (I don't remember exactly what CE was missing, but it was important to the project), you should review the functional differences.
Another advantage was the db was stored in the user folder which makes it impossible for other non-admin users of the laptop to see. This allowed us to reuse and even share laptops between users without mixing data - a nice feature.
Finally, the dbs (with a little effort) can be copied to the dev/support side and restored/attached for troubleshooting. They are full .mdf/.ldf database files.
You do have to create the instances using a command line (sqllocaldb utility), after the product is installed. This was just part of our install app.

Visual Studio keeps asking to install SQL Server

I am using Visual Studio 2012 working on a web application, a registration page. I have installed SQL Server 2008 Express and done the configuration but still when when I try to add a SQL Server database file in the project, I get an error
Connection to SQL Server Database file (.mdf) requires SQL Server 2005 or SQL Server 2008 Express to be installed and running on you local computer
Please help I am stuck here.
You need to install the LocalDB or to change your connection string to use the SQL server you have installed, it seems like you are trying to use a MDF file.

Error 948 :Visual Studio 2012 with SQL Server 2008 R2

I have a computer that working as server and client machine. I installed SQL Server 2008 R2 and Visual Studio 2012 in it.
Using SQL server management studio I generated a DB then I created few table in that DB , then I insert data into it.
Then I deattached that DB using Server Management studio . Then I move that DB into my project "App_Data" folder.Then using "server explorer" & T_SQL pane functions of Visual Studio 2012 I did few changes of that DB .
Since I want to do massive changes , I close that DB connection with the project. I move that DB into SQL server default Database Location which is
"C:\Program Files\Microsoft SQL
Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA"
then I try to attach that DB using server management studio , I'm getting
"Error 948"
Cannot be opened because it is version 706. This server supports
version 661 and earlier
How to overcome this error ? your ideas/suggestions highly appreciate
By default, you can't attach a DB file from a SQL Server 2012 to an instance which is running SQL Server 2008 R2.
Version 661 is a SQL Server 2008 R2 DB file and version 706 is a SQL Server 2012 DB file. More information: How to determine version of Local Sql Instance and your database
You will therefore need to update your SQL Server instance, e.g. by upgrading to SQL Server 2012
I would also recommend you patch to the newest released build of SQL Server 2012. Check here for the newest version numbers for the different SQL Server versions: Microsoft SQL Server Version List
its a version comparability issue.
Initially you created in sqlserver 2008 R2 that version would be 661 and when you moved to VS2012 it was updated to 706, and when you tried to go back to SQl server 2008 R2 again this 706 version is not being downgraded to 661, obviously it can't be done.
one simple solution without any changes to your server setup, use Generate Script feature that should help you.

how to automatically create aspnetdb.mdf to store administration security data

i was trying the MVC Music Store project but i encountered a problem when going to the administration tool, it says
There is a problem with your selected data store. This can be caused by an invalid server name or credentials, or by insufficient permission. It can also be caused by the role manager feature not being enabled. Click the button below to be redirected to a page where you can choose a new data store.
The following message may help in diagnosing the problem: Unable to connect to SQL Server database.
I searched online and tried numerous ways and found out it is because i don't have sqlserver express edition, so i can't use the AttachDbfile feature to auto create aspnetdb.msd file to store administration data
as i stated in the title, the truth is i installed sql server 2012 express first, but because i need reporting services i then installed the full sqlserver 2012, but i didn't create a new instance when installing instead i selected adding new feature to existing instance, so why does the VS say i don't have the express version now, i am totally buffled
does this mean if i want to use the app_data file feature again, i have to install sql server 2012 express as a new instance again?
SQL Server Express Edition is the only edition of SQL Server that supports User Instances. Thus, if you want to use a User Instance and do not have SQL Server Express Edition installed, you must install SQL Server Express Edition.
If you have a "full" version of SQL Server, I would suggest using the ASP.NET SQL Server Registration Tool (aspnet_regsql.exe) to create the equivalent of the aspnetdb.mdf database.
Edit:
As indicated in the answer to Can we install Express edition and Standard edition of SQL Server on same PC User?, it is possible to install both SQL Server Express Edition and a "full" version of SQL Server on the same computer.
However, it sounds like you performed an Edition Upgrade which replaced SQL Server Express Edition with the "full" version of SQL Server. If this is the case and you still want to use a User Instance, install SQL Server Express Edition again.
If you are not sure which edition(s) of SQL Server is installed, see How to determine the version and edition of SQL Server and its component.

C#.net db connection with sql server 2005 MDF file

After creating the setup file in c#.net WPF application, couldnot connect with the sqlserver 2005 MDF file.
The setup file is including the sqlserver MDF file.
plz tell me, what is connection problem?
Just a wild guess (see comments on your question): You're trying to use the "user instance" feature that was introduced in SQL Server 2005? Then the SQL Server 2005 needs to be installed on the target machine as well - maybe only the Express edition. As long as you don't install the SQL Server there's no way you get a connection to your shipped MDF file.

Categories