?
Solved

Howto access data within .NET SQL function?

Posted on 2007-04-03
1
Medium Priority
?
221 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
[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
1 Comment
 
LVL 10

Accepted Solution

by:
RichardCorrie earned 100 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

777 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