Solved

Howto access data within .NET SQL function?

Posted on 2007-04-03
1
209 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 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

12 Experts available now in Live!

Get 1:1 Help Now