Locate database - c#

I have used SQL Server Management Studio to convert an Access file to SQL Server. I want to add this database to a project using C# (it appears in Server Explorer - Data Connections).
When I use C#, Solution Explorer - Properties - AddResource - Add Existing file I am required to navigate to the database file, but I cannot locate it.
Database is RWJ-PC.PaulsNewDatabase.dbo. Please advise if possible.

Somewhere on your hard disk (or in a network folder)is a file with an extension of mdf. Attach the file to your SQL Server (using SQL Server Management Studio) instance and you will have a a database. SQL Server databases live on the file system as a mdf and (possible one or more ndf) file(s). It lives in memory and can be used when attached to a SQL Server instance.

C:\ProgramFiles\MicrosoftSQLServer\MSSQL12.MSSQLServer\MSSQL\Data\Filename
Found eventually by trolling the internet

If you have imported the data into an instance of SQL server you can connect to the instance of SQL or to the mdf. Look here --
How do I connect to an MDF database file?
Search for connecting to SQL Server with C# (VB.Net). You can use Entity Frame work or connect directly.

Related

Using data connections in Visual Studio to explore SQL Server Express database

I am using Entity Framework in order to create my models, but when I try to access the database from the data connections in Server Explorer, it does not work. I know the models are being created in the SQL Server Express instance running on my local machine, as I navigated to
Computer -> Program Files -> Microsoft SQL Server -> MSSQL10.SQLEXPRESS -> MSSQL -> DATA ->
and the database is in there.
Shouldn't my local instance of SQL Server Express show up in this window?
I read over this article from Microsoft which explains where database is stored.
Under server name type in \\\SQLEXPRESS or .\SQLEXPRESS (assuming you have installed the instance with default values)
then you should be able to access the database from the dropdown list.
you need to select your machine name from the Server Name dropdown as shown in below picture.
if your server is not showing in the list then simply open SQL Server note down that Server Name and write it Manually.
Here is an Example

C# / SQL Server - can't have two connections simultaneously to one database?

If I have SQL Server Management Studio open to my database, I can't open the database in my C# program because it will throw an error. I have to close the connection in Management Studio.
Is there a way to be able to connect to a single database with multiple connections?
This is just a local .mdf file on my computer that I'm working with.
The problem is that you connect with a user instance, which is single-user only and normally used just for development:
User instance scenarios include:
Any single-user application where sharing data is not required.
Reference: http://msdn.microsoft.com/en-us/library/ms254504.aspx
So your default SQL Server instance has the database open in your Management Studio session. When your program creates a new instance it can't access the database file because it is open with a different instance.
You can try using your server tool in Visual Studio to manage your database instead of Management Studio.
You should avoid connecting directly to the .mdf file. Have SQL Server host the database, and then connect to it from there rather than the file.

application with setup file with out SQL Server database

I have a windows application which is uses SQL Server as its database. For this application I want to create a setup file for other desktops, but I don't want to install SQL Server on each and every client.
Can you please suggest how to create Windows application with local storage setup file without installing any databases or framework libraries?
You can use SQL Server Compact. The database is stored in a file that you carry with the product rather than requiring a database server.
If this is just for "settings" then consider storing it in the user's application data as a simple XML file.
You don't need to install SQL Server on each client - you can simply install it on a central server then all the clients can connect to and use the same instance.
If this is not a good option because each client must have its own storage locally then you can look to use something like SQL Server Compact, which is a very cut down version of SQL Server that doesn't require installation and runs inproc.

How to use backup .sql file to add databse to sql server using C# console application?

I was working on a project where i made a database on sql server 2008 using visual studio 2010 and i took backup of that databse by right clicking on it in sever explorer and selecting "Publish to Provider" that creates a .sql file in my computer that i taken. Previously i formatted my pc and sql server databases are lost, so now i want to use that .sql file to recreate the database with all data, but i don't know how it can be possible.
Something i tried but it created all tables in master database but i want the database of the name i.e. stored in .sql file or specified by me.
Please help.
First Create a Database using this,
Create Database YOURDBNAME
Here, YOURDBNAME = DataBase Name
Then, Open your .sql file write this in First line of the .sql page,
Use YOURDBNAME
Now press F5, all the tables and data will be created and inserted.
You can use the SQL Server Management Objects libraries to manage all aspects of SQL Server.
SQL Server Management Objects (SMO) is a collection of objects that are designed for programming all aspects of managing Microsoft SQL Server. SQL Server Replication Management Objects (RMO) is a collection of objects that encapsulates SQL Server replication management.
From your description, however, this can be overkill. You get simply use SQL Server Management Studio (link goes to the free Express edition download), connect to the server, open a new Query Window with your SQL file and run it (F5).

changing the location of C# code files along with db

I have an application written in c# [WPF] which involves lot of communication with several databases, hence i used SQL server 2008. Now i need to move the code files along with the database files to another system(it doesn't have sql server installed). Once i run the applications exe , it gets struck as it is not able to retrieve data from .mdf file.
Is it possible to access sql server 2008 installed in my system through a network ?
It is pretty simple . I think you are using .mdf files as your database. Instead of it use .sdf as the database format which is mostly used in mobile development. There are lots of .mdf to .sdf converter available in the net.
You can have the second system access the SQL Server of the first system.
You need to modify the connection string so that it accesses a server on a remote machine, and make sure the proper authentication mechanism is used. If both machines are on the same Winodws domain, it's going to be fairly simple.

Categories