Bonjour,

Je code en C# 2.0 et j'essaie de créer par programmation une BDD SQLServer sur un serveur déjà existant. Une des méthodes consiste à se looger en admin, puis de créer sa base.

Les commandes à taper consécutivement sont les suivantes :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
// Login
osql –U sa –P password –S localhost\myinstance
// Creation de la base
use master
go
CREATE DATABASE Test
go
Mon souci : la classe Process requiert un nom de fichier valide, alors que les commandes osql n'ont pas ce pré requis. En gros, le code suivant génère une SqlException "Le fichier spécifié est introuvable."

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Get the database password
string strPassword = Context.Settings.Get(
    Constants.Settings.Name.Password,
    Constants.Settings.DefaultValue.Password);
 
// Create a new Process instance
Process objExecution = new Process();
 
// Initializes the Process object
objExecution.StartInfo = new ProcessStartInfo();
objExecution.StartInfo.FileName = "osql";
objExecution.StartInfo.Arguments = "–U sa –P " + strPassword + " –S " +
    strDatasource;
objExecution.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
 
// Launch the command
objExecution.Start();
 
// Initializes the Process object
objExecution.StartInfo = new ProcessStartInfo();
objExecution.StartInfo.FileName = "use";
objExecution.StartInfo.Arguments = "master";
objExecution.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
 
// Launch the command
objExecution.Start();
 
// PETAGE
Bref, rien de surprenant : "use" n'est pas un fichier valide ... Quelle est la solution à mon problème? Comment envoyer les commandes osql autrement que par Process? Merci d'avance ...