Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Visual Studio VB App with SQL Server 'Local' .mdf

Status
Not open for further replies.

Darrylles

Programmer
Feb 7, 2002
1,758
GB
Windows 7
MS Visual Studio Community 2015
MS SQL Server 2014
50 year old bloke - stuck in my old ways.

I have lot's of experience with MS Access VBA etc, but have a requirement to learn Visual Studio VB (or C#) connecting to 'local' (SQL Server) .mdf (file based tables).
It seems that 'local' (.mdf) databases aren't too prevalent (judging from my search results - or lack of them).
I've arrived at this solution requirement after much research and due to these attributes / limitations / tools available:

1) The compiled VS application can be packaged / deployed with 'file based' table definitions as opposed to SQL Server database tables (pretty much self-contained - apart from requiring a SQL Server instance).
2) These 'file based' tables can be handled by a SQL Server instance (without any objects having to be defined within SQL Server itself).
3) The SQL Server application is used for another, completely separate application, but, we have admin rights to it, thus can authorise user access to 'instances'.
4) To be clear: the .mdf's are LOCAL, FILE-BASED objects - with data-manipulation handled by calls via a SQL Server instance.
5) The reason we can't simply create tables, views, etc in SQL Server itself, is that it is 'ring-fenced' for one, specific application (although we can use the 'engine' as long as we don't store anything in there).
6) This SQL Server instance control of a 'local database' IS the optimum solution - I'll forget the project rather than use another 'flat-file' MySQL solution etc. (I have very high 'security' limitations, accompanied by the usual, extremely bureaucratic hurdles).

Learning problem:
I'm used to creating 'querydefs' (dynamic queries) and executing them in MS Access VBA. E.g. (SET rst = db.openrecordset("SELECT * FROM tableX")).
All examples found seem to insist on SQL Server table connection etc. (Which may be the same syntax-ish for local tables, but, I need a clear example).
Can anyone point me to a code example of creating a dynamic query at run time (much like the MS Access VBA 'querydef'), and connecting to the above .mdf 'local' database type, using VB or C#?
(I'm sure that it MUST exist, and one single example will put me on a path to discovering everything else that I need to learn).

Any pointers much appreciated, in the mean-time - I'll continue to Google.

Darrylle ;-)

P.S. Instead of making it look like this thread has had an answer (by adding a reply), I'll add any progress within the question (for now). I have come across this: which 'seems' to offer a possible example. I'll see ;-)
 
This is an old thread so i doubt it is an issue any longer. I just hate to see it go unanswered.




Simi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top