Solved

Accessing a MSSQL 2008 DB in C#

Posted on 2011-02-28
8
621 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 
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
 
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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
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 documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

696 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