Sei sulla pagina 1di 47

WINDOWS SERVER 2003

Documento di configurazione Infrastruttura

Indice generale
1. Setting up a DHCP server in Windows 2003................................................................................1
1.1 - Setting up a DHCP Server...................................................................................................................1 1.2 - Configuring a DHCP server.................................................................................................................6

2. Active Directory..............................................................................................................................8
2.1 Domain Setting...................................................................................................................................8 2.2 Active Directory...............................................................................................................................17 2.3 Adding a Computer to Active directory............................................................................................21 2.4 - Adding a Windows XP computer to a Windows Server 2003 domain ..............................................23 2.5 - Adding a Windows 2000 computer to a Windows Server 2003 domain ...........................................26

3.1 - Setting up Perl/CGI to work with Windows Server 2003 ....................................................29 3. Recupero valori da Gridview Field e HiddenField....................................................................36 4. Inserire il numero di record.........................................................................................................36 5. Inviare e recuperare parametri da querystring.........................................................................37 6. Codice bottone Search..................................................................................................................39 7. Una ricerca completa....................................................................................................................39 7. Uso del coalesce per ottenere una stringa completa da colonna tabella..................................41 8. Uso del try catch in una query sql...............................................................................................42

iii

iv

1. Setting up a DHCP server in Windows 2003


"Dynamic Host Configuration Protocol (DHCP) is an IP standard designed to reduce the complexity of administering IP address configurations." - Microsoft's definition. A DHCP server would be set up with the appropriate settings for a given network. Such settings would include a set of fundamental parameters such as the gateway, DNS, subnet masks, and a range of IP addresses. Using DHCP on a network means administrators don't need to configure these settings individually for each client on the network. The DHCP would automatically distribute them to the clients itself. The DHCP server assigns a client an IP address taken from a predefined scope for a given amount of time. If an IP address is required for longer than the lease has been set for, the client must request an extension before the lease expires. If the client has not requested an extension on the lease time, the IP address will be considered free and can be assigned to another client. If the user wishes to change IP address then they can do so by typing "ipconfig /release", followed by "ipconfig /renew" in the command prompt. This will remove the current IP address and request a new one. Reservations can be defined on the DHCP server to allow certain clients to have their own IP address (this will be discussed a little later on). Addresses can be reserved for a MAC address or a host name so these clients will have a fixed IP address that is configured automatically. Most Internet Service Providers use DHCP to assign new IP addresses to client computers when a customer connects to the internet - this simplifies things at user level.

1.1 - Setting up a DHCP Server


This will serve as a step-by-step guide on how to setup a DHCP server. Installing the DHCP server is made quite easy in Windows 2003. By using the "Manage your server" wizard, you are able to enter the details you require and have the wizard set the basics for you. Open to "Manage your server" wizard, select the DHCP server option for the list of server roles and press Next. You will be asked to enter the name and description of your scope.

Scope: A scope is a collection of IP addresses for computers on a subnet that use DHCP.

The next window will ask you to define the range of addresses that the scope will distribute across the network and the subnet mask for the IP address. Enter the appropriate details and click next.

You are shown a window in which you must add any exclusions to the range of IP addresses you specified in the previous window. If for example, the IP address 10.0.0.150 is that of the company router then you won't want the DHCP server to be able to distribute that address as well. In this example I have excluded a range of IP addresses, 10.0.0.100 to 10.0.0.110, and a single address, 10.0.0.150. In this case, eleven IP's will be reserved and not distributed amongst the network clients.

It is now time to set the lease duration for how long a client can use an IP address assigned to it from this scope. It is recommended to add longer leases for a fixed network (in the office for example) and shorter leases for remote connections or laptop computers. In this example I have set a lease duration of twelve hours since the network clients would be a fixed desktop computer in a local office and the usual working time is eight hours.

You are given a choice of whether or not you wish to configure the DHCP options for the scope now or later. If you choose Yes then the upcoming screenshots will be of use to you. Choosing No will allow you to configure these options at a later stage.

The router, or gateway, IP address may be entered in next. The client computers will then know which router to use.

In the following window, the DNS and domain name settings can be entered. The DNS server IP address will be distributed by the DHCP server and given to the client.

If you have WINS setup then here is where to enter the IP Address of the WINS server. You can just input the server name into the appropriate box and press "Resolve" to allow it to find the IP address itself.

The last step is to activate the scope - just press next when you see the window below. The DHCP server will not work unless you do this.

The DHCP server has now been installed with the basic settings in place. The next stage is to configure it to the needs of your network structure.

1.2 - Configuring a DHCP server


Hereunder is a simple explanation of how to configure a DHCP server. The address pool displays a list of IP ranges assigned for distribution and IP address exclusions. You are able to add an exclusion by right clicking the address pool text on the left hand side of the mmc window and selecting "new exclusion range". This will bring up a window (as seen below) which will allow you to enter an address range to be added. Entering only the start IP will add a single IP address.

DHCP servers permit you to reserve an IP address for a client. This means that the specific network client will have the same IP for as long as you wanted it to. To do this you will have to know the physical address

(MAC) of each network card. Enter the reservation name, desired IP address, MAC address and description choose whether you want to support DHCP or BOOTP and press add. The new reservation will be added to the list. As an example, I have reserved an IP address (10.0.0.115) for a client computer called Andrew.

If you right click scope options and press "configure options" you will be taken to a window in which you can configure more servers and their parameters. These settings will be distributed by the DHCP server along with the IP address. Server options act as a default for all the scopes in the DHCP server. However, scope options take preference over server options. In my opinion, the DHCP server in Windows 2003 is excellent! It has been improved from the Windows 2000 version and is classified as essential for large networks. Imagine having to configure each and every client manually - it would take up a lot of time and require far more troubleshooting if a problem was to arise. Before touching any settings related to DHCP, it is best to make a plan of your network and think about the range of IPs to use for the computers.

2. Active Directory
2.1 Domain Setting
One of the greatest features of Windows Server 2003 is its ability to be a Domain Controller (DC). The features of a domain extend further than this tutorial ever could, but some of its most well known features are its ability to store user names and passwords on a central computer (the Domain Controller) or computers (several Domain Controllers). In this tutorial we will cover the "promoting" (or creating) of the first DC in a domain. This will include DNS installation, because without DNS the client computers wouldn't know who the DC is. You can host DNS on a different server, but we'll only deal with the basics.

Method:
Click Start -> Run...

Type "dcpromo" and click "OK"

You will see the first window of the wizard. As it suggests, I suggest reading the help associated with Active Directory. After this, click "Next"

Click "Next" on the compatibility window, and in the next window keep the default option of "Domain Controller for a new domain" selected, and click "Next"

In this tutorial we will create a domain in a new forest, because it is the first DC, so keep that option selected

Now we have to think of a name for our domain. If you own a web domain like "visualwin.com", you can use it, but it isn't suggested because computers inside of your domain may not be able to reach the company website. Active Directory domains don't need to be "real" domains like the one above - they can be anything you wish. So here I will create "visualwin.testdomain"

10

Now in order to keep things simple, we will use the first part of our domain ("visualwin"), which is the default selection, as the NetBIOS name of the domain

The next dialog suggests storing the AD database and log on separate hard disks, and so do I, but for this tutorial I'll just keep the defaults

11

The SYSVOL folder is a public share, where things like .MSI software packages can be kept when you will distribute packages (as I said, AD has a lot of different features). Once again, I will keep the default selection but it can be changed if you wish to use the space of another drive

Now we will get a message that basically says that you will need a DNS server in order for everything to work the way we want it (i.e., our "visualwin.testdomain" to be reachable). As I mentioned earlier, we will install the DNS server on this machine as well, but it can be installed elsewhere. So keep the default

12

selection of "Install and configure", and click "Next"

Because, after all, this is a Windows Server 2003 tutorial website, we'll assume there are no pre-Windows 2000 servers that will be accessing this domain, so keep the default of "Permissions compatible only with Windows 2000 or Windows Server 2003 operating systems" and click "Next"

The restore mode password is the single password that all administrators hope to never use, however they

13

should also never forget it because this is the single password that might save a failed server. Make sure it's easy to remember but difficult to guess

Now we will see a summary of what will happen. Make sure it's all correct because changing it afterwards can prove to be difficult

After the previous next was clicked, the actual process occurs. This can take several minutes. It's likely that you will be prompted for your Windows Server 2003 CD (for DNS) so have it handy

14

If your computer has a dynamically assigned address (from DHCP) you will be prompted to give it a static IP address. Click ok, and then in the Local Area Connection properties, click "Internet Protocol (TCP/IP)" and then "Properties"

In the next window select "Use the following IP address" and select the information that you will use for your domain (and 127.0.0.1 for the primary DNS, because your computer will host DNS. I still suggest setting up an alternate as well.) Click "OK" and then "Close" on the next window

15

And after a while you will see

And we're finished.

16

2.2 Active Directory Preface:


As you know, if you try to add AD users using lusrmgr.msc you will receive the following error:

And since I cover creating a local user (lusr) I thought it would only be right to cover creating an Active Directory user.

17

Method:
Click Start, highlight "Administrative Tools" and select "Active Directory Users and Computers"

Now, expand your domain name on the left side, and go to the bottom where it says "Users". Once you click on that, you will see all of the automatically created users, you will also see all of the users you made before you ran dcpromo - that's because they all stay through the promotion to DC. Anyway, to add a user, you can either right click the "Users" folder on the left side, or the blank area on the right side, and highlight "New" then click "User"

18

In the next dialog we can set the user's First name, Last name and various other pieces of information, including their log-on name, and domain to which we want to add them

19

After clicking "Next" you are presented with the password-settings screen. You can set the user's password and then have them change it on their first log-on by selecting "User must change password at next logon". But in this tutorial, I will set it as their password, and not allow them to ever change it without asking me (the administrator) to change it for them

In the next dialog, we get a summary of the user to be created. Click "Finish" and the user has been created

And we're finished!

20

2.3 Adding a Computer to Active directory Preface:


Earlier, I showed you how to add users to your Active Directory domain. This tutorial will focus on how to add computers. This step is not "really" necessary for workstation computers - at least, I was able to add a Windows XP machine to my domain without adding the computer name first. This is section is really for looking at which computers join, and allow other servers to join as DC's, etc. I will show you how to add the computer using "Active Directory Users and Computers", then in other tutorials, I will demonstrate how to add a Windows 2000 computer and Windows XP computer to this domain. "By default a computer will get dumped in the Computers container, unless a Windows 2003 Native Mode Domain is inplace, and redircomp has been run to change this. Precreating computer accounts in OUs will ensure that when the unit is joined, it is in the correct OU, which guarantees policy consistency, and other administrative things. One can also specify who can reset the machines password. This will allow an admin to create an account for a computer, and let a normal user join the machine with their credentials."

Method:
Click Start, highlight "Administrative Tools" and select "Active Directory Users and Computers"

21

Expand your domain name, and right-click "Computers", highlight "New" then click "Computer"

In this dialog we have to type the name of the computer we want to add

In the next dialog just click "Next", then you will see a final report of what will be added, and you can click "Finish". And, we're done!

22

2.4 - Adding

a Windows XP computer to a Windows Server 2003 domain

Preface:
This is basically the same procedure as the Windows 2000 tutorial. Some things to note about adding a Windows XP computer to a domain are the following: You need Windows XP Professional to join a XP computer to a domain. Home can't be used fully for this You will loose the "fancy" log on screen and you will receive the "classic" log on screen instead. This is for security and cannot be changed, unless you revert to workgroup mode You will loose the "Fast User Switching". This cannot be restored, except by reverting back to workgroup mode.

Method:
Click Start, right click "My Computer" and click "Properties"

Go to the "Computer Name" tab and click "Change..."

23

Select the "Domain" radio button then put in your domain name, not including the . extension (in my example I used the domain "hello.test" but when joining the computer to a domain, I will only type "hello")

Press "OK". Then you will be presented with a user name and password prompt. Enter the user name and password of a Domain Administrator

24

Press "OK" and after a minute or two you will receive a message welcoming you to the domain. Then you will receive a message telling you that a reboot is required, click "OK" to that, and the properties window. Then click "Yes" when you are prompted to reboot. And we're finished. You have just learnt how to add a Windows XP computer to a Windows Server 2003 domain

Additive:
After the XP computer boots to Control-Alt-Delete you may need to change it from logging onto itself (which will use the local info) to logging onto the domain. To do this, press Ctrl-Alt-Del, then the "Options >>>" button on the log on screen. Then select the domain from the drop-down box

After that you can log on using domain credentials

25

2.5 - Adding Preface:

a Windows 2000 computer to a Windows Server 2003 domain

I have already shown you how to add AD users and computers to a Windows Server 2003 Active Directory domain, in this tutorial I will show you how to add a Windows 2000 computer to the domain. The method for adding Windows XP is basically the same, but I have created another tutorial for XP which is available here.

Method:
On the Windows 2000 computer, go to the desktop and right click "My Computer" and select "Properties"

In the dialog that comes up, go to the "Network Identification" tab and press the "Properties" button

26

Under "Member of" click the "Domain" radio button, then type the name of your domain without the trialing extension (for example, my domain name is "hello.test" but I only typed in "hello"

27

Now you will be prompted to put in the user name and password of a Domain Administrator. Enter the correct information, and press "OK"

Now, wait for about a minute or two and you should receive this message welcoming you to the domain

That's it, press "OK" then "OK", then "OK" in the configuration dialog, and finally "Yes" to reboot and you will be able to log onto the domain using an AD user name and password (not the local 2000 password) to log on.

Additive:
After the 2000 computer boots to Control-Alt-Delete you may need to change it from logging onto itself (which will use the local info) to logging onto the domain. To do this, press Ctrl-Alt-Del, then the "Options >>>" button on the log on screen. Then select the domain from the drop-down box

After that you can log on using domain credentials

28

3.1 - Setting up Perl/CGI to work with Windows Server

2003
The following things are assumed: 1. You are running Windows Server 2003 2. IIS 6.0 3. You installed ActiveState ActivePerl (http://www.activestate.com) to C:\Perl UPDATE: ActivePerl 5.8.2 Build 808 and higher should add the Web Service Extensions during install 4. You are using default (unmodified) ACLs/Permissions Also, all of my reasoning is explained after the step-by-step is done, at the bottom of the page. Load IIS from the Administrative tools in the Control Panel by clicking Start -> Administrative Tools -> IIS Manager (or loading the Control Panel, entering the Administrative Tools folder, and double clicking IIS Manager).

Click the name of your computer then click "Web Service Extensions", on the left side of the main frame you will see a green arrow pointing to a link that says "Add a new Web service extension...", click that link.

29

In that window, where it asks for the extension name you can put anything, like "CGI script" and under the "Required Files" section put the following in (without the apostrophes) 'C:\Perl\bin\perl.exe "%s" %s' click OK to the notification, click "Set status to allowed" and press ok.

Now, load up a command prompt (Start->Run... type cmd) and type (without the quotes) "md c:\inetpub\cgi-

30

bin"

Back in the IIS Manager right click Default Web Site highlight "New" in the pop-up menu and click "Virtual Directory..." in the new menu

31

Click next to the first dialog in the wizard, then as a the alias put "cgi-bin" and click next then as a path for the next dialog put in "c:\inetpub\cgi-bin". On the next dialog leave everything checked and check execute and click next

32

Click Finish to end the wizard. Now right-click cgi-bin and click properties

Click Configuration in the lower right-hand area of the dialog and make sure .pl is there (if it isn't, add it the way you see it)

33

Making your scripts work


To make your scripts work the shebang line (#!/usr/bin/perl) should now be #!C:\Perl\bin\perl.exe . Any reference to any files should be changed from /home/user etc, to c:/home/user or c:\\home\\users - note the double back-slashes. Also, renaming your .cgi scripts to .pl is highly recommended - it's what I do myself ;-) Assuming this is all done correctly, you should now be able to run your Perl scripts successfully using Windows Server 2003, and IIS 6.0

My reasoning
Q: Why do you make cgi-bin in \inetpub and not in \inetpub\wwwroot even though you're going to be making a Virtual Directory there anyway? A: The reason I go through these extra few steps are (1) To bring in a Command shell (open one of those and you immediately look smart, plus it makes things go wwaaayyy quicker) (2) I got it from the *nix world, what can I say, back when I hosted on Linux that's the way the directories were set up, so it stayed with me bottom line is, you don't need it like that, it's just the way I prefer. Q: Why do you have a cgi-bin folder at all? A: It is always better to keep your scripts separate from your regular files. Q: If you know that ActivePerl 5.8.2 Build 808 and higher automagically add the service extensions, why do you still have this tutorial? A: Many reasons. First, this tutorial isn't only for Perl, but for anything similar. Second, just in case :-)

34

Per poter usare il calendario usare ajaxToolkit


<asp:TextBox CssClass="textBoxData" runat="server" ID="txtPlannedAt" /> <ajaxToolkit:CalendarExtender ID="CalendarPlannedAt" runat="server" Enabled ="True" TargetControlID="txtPlannedAt" CssClass="MyCalendar" FirstDayOfWeek = "Monday" Format="dd/MM/yyyy" PopupButtonID="imgPlannedAt" /> <asp:Image runat="server" ID="imgPlannedAt" ImageUrl="~/Images/calendar_month.png"/> <asp:CustomValidator ID="cvPlannedAt" runat="server" ErrorMessage='<%$ Resources:Localization, ERROR_InvalidDate%>' ValidationGroup="InitiativeListValidate" ControlToValidate="txtPlannedAt" ValidateEmptyText="false" OnServerValidate="cvPlannedAt_ServerValidate"> </asp:CustomValidator>

Viene fatto click sull'immagine associata al calendarietto e cos si apre il popup relativo. Il validatore un customValidator e ha bisogno della seguente funzione personalizzata che valida la data
protected void cvPlannedAt_ServerValidate(object source, ServerValidateEventArgs args)
{

bool retValue = true; DateTime d; if(!DateTime.TryParse(txtPlannedAt.Text, out d))


{

txtPlannedAt.Text = "";
}

if (!(DateTimeFormatter.IsDateTime(txtPlannedAt.Text)))
{

cvPlannedAt.ErrorMessage = Resources.Localization.ERROR_InvalidDateField; retValue = false;


} args.IsValid = retValue;

35

} Il validatore permette di validare una data in formato gg/mm/aaaa se per caso viene scritto CICCIO allora

non verr validato nulla.

3. Recupero valori da Gridview Field e HiddenField


Per poter recuperare valori da gridview necessario eseguire la funzione FindControl. Ecco il caso per un campo nascosto in griglia :
GridViewRow row = (sender as ImageButton).Parent.Parent as GridViewRow;

e prendere :
HiddenField hdfInitiativeCode = (HiddenField)row.FindControl("hdfInitiativeCode"); initiativecode = hdfInitiativeCode.Value;

invece per un campo non nascosto : string message = (string)row.FindControl(message); Per recuperare da code behind un valore di una dropdownlist invece :
responsible = ddlResponsible.SelectedValue.ToString();

4. Inserire il numero di record


Per poter inserire il numero di record necessario inserire due label con allieneamento a destra e fare l'overload del metodo di objectdatasource onSelected=odsInitiativesList_Selected
protected void odsInitiativesList_Selected(object sender, ObjectDataSourceStatusEventArgs e) { int recordCount = ((DataTable)e.ReturnValue).Rows.Count; NrRecords = recordCount.ToString(); lblRecordCount.Visible = (recordCount != 0); lblRecordCountValue.Visible = (recordCount != 0); lblRecordCountValue.Text = NrRecords; }

e definire NELLA GRIDVIEW (non nell'objectdataSource)


OnDataBound="gdvInitiativesList_DataBound"
protected void gdvInitiativesList_DataBound(object sender, EventArgs e) { this.lblRecordCountValue.Text = NrRecords;

36

5. Inviare e recuperare parametri da querystring


Per poter inviare parametri ad una pagina necessario usare il Response.write e costruire la querystring,.
QueryString = "InitiativeCode=" + initiativecode + "&Title=" + title + "&Responsible=" + responsible + "&InitiativeTarget=" + initiativetarget + "&LdmCode=" + ldmcode + "&PlannedDate=" + planneddate + "&InitiativeStatus=" + initiativestatus + "&StatusOfCentralization=" + statusofcentralization; Response.Redirect("NpsInitiativeManagement.aspx?" + QueryString);

Per poterli ricevere invece nel PageLoad bisogna fare cos :


protected void Page_Load(object sender, EventArgs e) { if (!(Page.IsPostBack)) { UserCode = CurrentApplicationUserHolder.CurrentApplicationUser.UserCode; //Etichetta di debug... lblUserCode.Text = UserCode; bool showFilterSection = false; txtTitle.Text = string.Empty; txtPlannedAt.Text = string.Empty; ddlResponsible.DataBind(); ddlScope.DataBind(); ddlStatusOfInitiative.DataBind(); ddlStatusOfCentralization.DataBind(); ddlLdm.DataBind(); // Recupero i valori passati dalla pagina di dettaglio if (!(string.IsNullOrEmpty(Request.QueryString["Title"])))

37

{ txtTitle.Text = Request.QueryString["Title"].ToString(); showFilterSection = true; } if (! (string.IsNullOrEmpty(Request.QueryString["Responsible"]))) { Responsible = Request.QueryString["Responsible"].ToString(); for (int i = 0; i < ddlResponsible.Items.Count; i++) { if (ddlResponsible.Items[i].Value == Responsible) { ddlResponsible.SelectedIndex = i; ddlResponsible.Items[i].Selected = true; break; } } showFilterSection = true; } //questo parametro siamo sicuri arriva.... LdmCode = Request.QueryString["LdmCode"]; for (int i = 0; i < ddlLdm.Items.Count; i++) { if (ddlLdm.Items[i].Value == LdmCode) { ddlLdm.SelectedIndex = i; ddlLdm.Items[i].Selected = true; break; } } // Se lo stato 0 allora chiudo il pannello if (ddlLdm.SelectedIndex != 0) { showFilterSection = true; } odsInitiativesList.DataBind(); updpnlNrRecord.Update(); if (showFilterSection) { ShowFilter(); }

38

6. Codice bottone Search


protected void btnSearch_Click(object sender, EventArgs e)
{

if (Page.IsValid)
{ odsInitiativesList.DataBind(); gdvInitiativesList.DataBind(); updpnlNrRecord.Update(); updpnInitiativesList.Update(); }

7. Una ricerca completa


ALTER PROCEDURE [dbo].[GetEmployee] @CodCompany ,@Surname ,@Name ,@BirthDateEnd ,@Active ,@SupervisorId AS BEGIN SELECT tbEmployee.CodResource ,tbEmployee.CodCompany ,tbEmployee.Surname ,tbEmployee.Name ,tbCompanies.CompanyName ,tbEmployee.BirthDate ,tbEmployee.Active int varchar(255) varchar(50) DateTime int int

,@BirthDateStart DateTime

39

,tbSupervisors.SuperVisorId ,tbSupervisors.SupervisorName FROM tbEmployee INNER JOIN tbCompanies ON tbEmployee.CodCompany = tbCompanies.CodCompany LEFT OUTER JOIN tbSuperVisors ON tbEmployee.SuperVisorId = tbSuperVisors.SuperVisorId WHERE ((tbEmployee.Active = @Active ) OR @Active = -1) -- Campi testuali AND (tbEmployee.Surname LIKE AND (tbEmployee.Name LIKE AND + '%' + @Surname + '%' OR @Surname IS NULL) ,tbEmployee.BirthDate) ,tbEmployee.BirthDate)) + '%' + @Name + '%' OR @Name IS NULL) ISNULL(@BirthDateStart ISNULL(@BirthDateEnd AND ((tbEmployee.CodCompany = @CodCompany ) OR @CodCompany = 0)

AND (tbEmployee.BirthDate BETWEEN

AND (tbSupervisors.SupervisorId = @SupervisorId OR (tbEmployee.SupervisorId IS NULL AND @SupervisorId IS NULL ) OR (@SupervisorId = 0)) ORDER By tbEmployee.Surname,tbEmployee.Name,tbEmployee.BirthDate END

La maschera la seguente :

((tbEmployee.CodCompany = @CodCompany ) OR @CodCompany = 0)

40

AND (tbSupervisors.SupervisorId = @SupervisorId OR (tbEmployee.SupervisorId IS NULL AND @SupervisorId IS NULL ) OR (@SupervisorId = 0))

In questa linea di codice si specifica una scelta puntuale OPPURE una scelta nulla (ossia il valore a database nullo e la scelta effettuata nulla) oppure la scelta a 0. Una alternativa alla seconda poteva essere :
(ISNULL(tbEmployee.SupervisorId,'') = '' AND @SupervisorId IS NULL) OR SupervisorId non valorizzato. -- con

7. Uso del coalesce per ottenere una stringa completa da colonna tabella
-- CODICE SQL PER COMPATTARE UNA TABELLA ALTER FUNCTION dbo.ChoiceToString ( @CodResource varchar(15) ) RETURNS varchar(Max) AS BEGIN DECLARE SELECT FROM WHERE END @result varchar(max) @result = coalesce(@result + ',', '') + SpecializationId tbImpSpec tbImpSpec.CodResource = @CodResource

RETURN @result

41

DECLARE @va varchar(max) SELECT @va = dbo.ChoiceToString ('ABALLAND') PRINT @va

La tabella la tabella tbEmpSpec ossia la tabella in cui sono memorizzate le scelte effettuate dall'utente.

8. Uso del try catch in una query sql


ReturnValue bit OUTPUT BEGIN TRY BEGIN TRANSACTION --- QUERY SET @ReturnValue = 0 COMMIT TRANSACTION; END TRY BEGIN CATCH ROLLBACK TRANSACTION; SET @ReturnValue = 1 END CATCH;

42