[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Accessing a MSSQL 2008 DB in C#

Posted on 2011-02-28
8
Medium Priority
?
624 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

649 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