Solved

Howto access data within .NET SQL function?

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

860 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