Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Install SMO or Alternative?
Message
From
15/03/2011 12:15:01
 
 
To
14/03/2011 17:41:45
General information
Forum:
ASP.NET
Category:
Databases
Environment versions
Environment:
VB.NET 1.1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01503651
Message ID:
01503737
Views:
48
Hi Gunnar,

There are several things you can do using classes in the System.Data.Sql and System.Data.SqlClient namespaces.

1) To get a list of all SqlServers on your network, use this:
DataTable dt = System.Data.Sql.SqlDataSourceEnumerator.Instance.GetDataSources();
The returned DataTable contains a column, ServerName.

2) You can use SqlConnection to get a list of the databases on a given server:
SqlConnectionStringBuilder csBuilder;
security = "Integrated Security=True"; 
csBuilder = new SqlConnectionStringBuilder(string.Format("server={0};{1}", ServerName, security))
using (SqlConnection connection = new SqlConnection(this.csBuilder.ConnectionString))
{
    connection.Open();
    this.dtDatabases = connection.GetSchema("Databases");
    connection.Close();

    // to get a list of tables in a database
    foreach (DataRow row in this.dtDatabases.Rows)
    {
	// for some reason, accessing the "model" database in this manner prevents the 
	// CREATE DATABASE from getting an exclusive lock on it, even though the connection gets closed
	// so we'll exclude it from this process
	if (row["database_name"].ToString().ToLower() == "model")
		continue;

	this.csBuilder.InitialCatalog = row["database_name"].ToString();
	connection.ConnectionString = this.csBuilder.ConnectionString;
	connection.Open();
	this.dtTableNames = connection.GetSchema("Tables", new string[] { null, null, null, "BASE TABLE" });
        // more code
    }
Now, that said, I've also utilized SMO for updating tables in databases and the like, but by using the above code for at least finding servers on the network, you may be able to tell whether you need to install SMO or not.

~~Bonnie



>Hello Everybody.
>
>I am currently writing my own setup/install routine. Mostly because it’s a very complex installation and I don't know how and if this can be done with the free install shield version.
>
>In this vb.net application, one part handles the SQL setup. For this, the program needs to:
>
  • collect all installed SQL instances on the network
    >
  • test connection string
    >
  • create a new database, table, views, UDF, and Database User
    >
  • list existing Databases and their tables
    >Currently I accomplish this via the SMO namespace. It works great!
    >
    >However, it only works great on my development machine because SMO is installed here through an SQL installation.
    >
    >The installation must be able to do all this without having to install an SQL (or express) instance.
    >
    >So, here are my questions:
    >
  • how to install "only" SMO manually?
    >
  • is there an alternative and/or a better way to accomplish the above tasks?
    >
    >As always I truly appreciate your help!
    Bonnie Berent DeWitt
    NET/C# MVP since 2003

    http://geek-goddess-bonnie.blogspot.com
  • Previous
    Next
    Reply
    Map
    View

    Click here to load this message in the networking platform