Solved

Howto access data within .NET SQL function?

Posted on 2007-04-03
1
213 Views
Last Modified: 2013-11-26
I'm trying to learn Visual Studio SQL Projects and have managed to create a project, connect to a database, create a UDF and the associated test script.  My question has to do with actually accessing the data.  How?

What's the best way to access data?  Currently I'm creating a SQLConnection, but this requires a connection string that only the calling application knows.  Since the project is built and deployed against a database using Windows authentication why do I need a connection string in the first place?  What if we deploy the assembly to another database, I don't want to hardcode the connection string.  There should be a default connect using the credentials given at deployment time setting shouldn't there?

Additionally I'm going to need to know how to create a temp table and cursor to iterate, or in C# iterate through a recordset, is there anywhere out there where sample C# code in SQL Projects has been collected?  

This seems like it's way harder than it should be.
0
Comment
Question by:StuTheDog
1 Comment
 
LVL 10

Accepted Solution

by:
RichardCorrie earned 50 total points
ID: 18849852
the .Net forum would probably be a better place to ask this type of question;but here goes:

1) Connection string: you will *always* need to tell your application which, where and how to connect to a database hence the connection string; u can use the ConnectionStringBuilder class (part of System.data) to set/get the correct properties or u can set the connection string as a Project setting (click the setting tab whn looking at the project properties) one of the "types" of setting is "connectionString".

part of the connection string is the security method (Windows or SQL) used to connect to the db

the settings are "deployed" in App.config file; you can ammend that file prior to/after deployment to change any value.

2) to iterate a recordset use a datareader object.

I would reccommend that u get a good book on .net data access to really get to grips with it.

/Richard
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

821 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