Solved

Howto access data within .NET SQL function?

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

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…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

733 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