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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace Database
{
class DatabaseUtility
{
/// <summary>
/// Get all Databases
/// </summary>
public static string[] GetDatabases(string connectionstring) {
List<string> databases = new List<string>();
SqlConnection conn = new SqlConnection(connectionstring);
try
{
// sp_helpdb storedprocedure auf Sql Server 2000 und Sql Server 2005
SqlCommand cmd = new SqlCommand("sp_helpdb", conn);
conn.Open();
SqlDataReader r = cmd.ExecuteReader(CommandBehavior.CloseConnection);
while (r.Read())
{
// an 1. Pos steht der dbname
string dbname = r[0].ToString();
databases.Add(dbname);
}
r.Close();
}
catch
{
// fehlerhandling
}
finally
{
conn.Close();
}
return databases.ToArray();
}
}
}
|