Microsoft Windows®XP -  Programmation ASP.NET

 

 

 Windows® XP -  Programmation ASP.NET (Suite)


Nous allons découvrir un petit exemple concret qui vous permettra de démarrer rapidement un environnement de base de données.
Créons une base de données à l’aide du client MSDE que nous avons téléchargé précédemment puis installé au sein de notre système.
Avant tout, nous allons assigner les permissions afin de pouvoir travailler.

Vous prendrez connaissance plus tard des informations suivantes, en anglais, expliquant comment assigner les permissions à votre environnement. Tout d’abord, ouvrez une Invite de commande et saisissez :

C:\>osql –E –S 857805-8a8 –Q "sp_grantlogin ‘857805-8a8\Patrice’"

857805-8a8 est mon serveur, 857805-8a8\Patrice le nom de l’utilisateur sur la machine en cours. La base de données se nomme ‘CLIENTS’ :

C:\>osql –E -S 857805-8a8 -d CLIENTS –Q "sp_grantdbaccess '857805-8a8\Patrice'"
C:\>osql –E -S 857805-8a8 -d CLIENTS –Q "sp_addrolemember 'db_owner', '857805-8a8\Patrice'"

Open an MS-DOS Command Prompt. Generally, this can be found using:

  Start Menu -> Run
  Type in: cmd.exe or command.exe depending on your OS

Inside of the MS-DOS Command Prompt you'll make use of a utility called OSQL to manage your new MSDE instance. Specifically, you'll be assigning permissions to the ASP.NET worker process account. The following commands will need to be run to properly assign permissions:

osql -E -S [SERVER] -Q "sp_grantlogin '[USERNAME]'"

osql -E -S [SERVER] -d [DATABASE] -Q "sp_grantdbaccess '[USERNAME]'"

osql -E -S [SERVER] -d [DATABASE] -Q "sp_addrolemember 'db_owner', '[USERNAME]'"

The following variable replacements are defined for the above statements:

[SERVER]

This should be the name of your database server. When you installed MSDE you got two choices. The first was to install a default instance of MSDE. If you chose this method then your instance name will be [MACHINENAME] or [MACHINENAME]\NetSDK. The second choice was to install to a custom instance, [MACHINENAME]\[CUSTOMINSTANCE].

[MACHINENAME]

When connecting to a SQL server, you can connect to either you machine or a remote machine using the OSQL tool. If you installed to your local machine then you can use the special name (LOCAL) or localhost to connect locally, or the actual name you've assigned to your machine. For remote machines, you'll need to specify a DNS name (sql1.mydomain.com), an IP address (192.168.0.1), or the NETBIOS name of the machine on your local network (SQLSERV1).

[CUSTOMINSTANCE]

Custom instances are a great new MSDE/SQL 2K feature. It allows the same machine to host multiple instances of the database server for testing and migration purposes. It also means applications can have their own server rather than simply having a database within an existing server. Various products shipped by Microsoft use the instance names NetSDK and VSDotNet, and so you may have databases with these names on your machine. You may have also installed using a custom instance name of your own, in which case you'll need to specify that when connecting to or modfiying the server.

In addition, you can use net commands from the command line in order to discover the SQL Servers on your machine assuming they are running.

 net start

The above command will list all currently running services. You'll need to search the list for services starting with MSSQL (the list is in alphabetical order). If any of the services contain a $ sign, followed by additional naming information, then the additional information after the $ sign is the instance name.

[DATABASE]

Each server you install will have multiple databases. You'll need to grant the worker process priveleges to any of the database it will be working with. Some common database names are master, northwind, pubs, grocertogo, AspNetForums, and portal.

[USERNAME]

The username will be the user you are assigning permissions for. You'll probably need to assign permissions to the [MACHINENAME]\ASPNET account. If you are using SQL security, or you are signing in using NT authenticated users that aren't the ASPNET account, then you'll need to replace the username with that information instead, examples include (sa, MyCustomDBUser, [MACHINENAME]\MyLogin, and DOMAIN\MyLogin).

 

Suivant Suivant