Solved

Accessing a MSSQL 2008 DB in C#

Posted on 2011-02-28
8
610 Views
Last Modified: 2012-05-11
I've been Installing/configuring MSSQL with TCPIP and accessing it just fine in C#.  But I've seen references that make me believe that it's possible to access a MSSQL .mdf file directly and not using named pipes or TCPIP.  Is this true?

It's come more to light while working on my install routing using innosetup.  In one of the examples I was referring to it appears that innosetup creates the DB outside of mssql 2008 express after mssql 2008r2 express was installed.

Then in another part I saw some code prototyping that appeared to access the MDF file directly.  Is this still using MSSQL 2008 just not the server or what?
0
Comment
Question by:sej69
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 8

Expert Comment

by:WesWilson
ID: 35000916
I would recommend continuing to use a standard connection string, not going after the .MDF file directly. I think you will find that more standard and more flexible, especially if you are developing an application that will be hosted eventually on a separate machine from the DB host machine.
0
 

Author Comment

by:sej69
ID: 35001290
I agree with you 100%; I'm just trying to get this straight in my head with different references to accessing the MDF file.  Is it possible and/or is it actually using MSSQL at this point or something in C# to access the MDF?
0
 
LVL 20

Expert Comment

by:Marten Rune
ID: 35005560
Weather it's possible or not is not the point.

The design of a database server (MS SQL, ORACLE, ySQL, DB2 etc) is to write to a log file first, and then have commit/rollback transactions. This is hotwired if you access the MDF file directly. I would STRONGLY argue against it.

There will not be any performancegain, and every other parameter is worse. Simply put, don't go that route!

//Marten
0
 
LVL 9

Expert Comment

by:mayank_joshi
ID: 35005745
yes its possible to access the mdf file directly.you can use the connection string like:-

Data Source=.\SQLEXPRESS;AttachDbFilename="C:\Databases\test.mdf";User ID=sa;Password=123;Connect Timeout=30;User Instance=True
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 9

Expert Comment

by:mayank_joshi
ID: 35005812
0
 
LVL 20

Expert Comment

by:Marten Rune
ID: 35005998
The following:

Data Source=.\SQLEXPRESS;AttachDbFilename="C:\Databases\test.mdf";User ID=sa;Password=123;Connect Timeout=30;User Instance=True    

Does not access the mdf file DIRECTLY. It accesses it through sql server (express). I e it's just another way to determine the database name, by sending the parameter of the mdf file to the server.

//Marten
0
 
LVL 9

Accepted Solution

by:
mayank_joshi earned 500 total points
ID: 35006322
Data Source=.\SQLEXPRESS;AttachDbFilename="C:\Databases\test.mdf";User ID=sa;Password=123;Connect Timeout=30;User Instance=True


martenrune,
i think it  does not use TCP/IP or Named Pipes and so it fullfills the requirement.
0
 

Author Closing Comment

by:sej69
ID: 35013911
Thanks, I was just trying to get my head around this in some of the documentation I was reading out there.  I'm going to stick with TCPIP connections but at least now I understand that the docs I was reading was referring direct access to the db file and can translate that into what I need.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now