Solved

Accessing a MSSQL 2008 DB in C#

Posted on 2011-02-28
8
613 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
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

863 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

19 Experts available now in Live!

Get 1:1 Help Now