Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
lionking88
Starting Member
3 Posts |
Posted - 2010-08-05 : 11:49:53
|
Hi,I'am having a problem triyng to use SMO to make a backup of my database.I use this to know the name of server:DataTable dt = SmoApplication.EnumAvailableSqlServers(true); foreach (DataRow dr in dt.Rows) { cbServers.Items.Add(dr[0].ToString()); srvName = dr[1].ToString() + "\\" + dr[2].ToString(); } srvName will get the name of Server (I just get one "RICARDO-PC\SQLEXPRESS" ), and then i use this to get the name of my databases and i just get:mastermodelmsdbtempdbHow can I extract other tables if I just can get "RICARDO-PC\SQLEXPRESS"? I have two more tables.Sorry, my English. |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-08-05 : 12:09:28
|
quote: and then i use this to get the name of my databases
How? No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-08-05 : 12:17:49
|
is this what you need?Database : SELECT db_name() AS MyDatabaseNameServer: SELECT SERVERPROPERTY ('InstanceName') AS MyServerNameor use 'MachineName', or 'ServerName' |
|
|
lionking88
Starting Member
3 Posts |
Posted - 2010-08-05 : 12:22:35
|
I get my system databases (master,model, msdb, tempdb ) with this:Server svr = new Server(@"" + srvName + ""); foreach (Database dbServer in svr.Databases) { cbServers.Items.Add(dbServer.Name); }srvName - RICARDO-PC\SQLEXPRESScbServers - DropDownList |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-08-05 : 12:25:14
|
SELECT [name] FROM sys.databaseswill give you all the databases on a server - if that is what you need? |
|
|
lionking88
Starting Member
3 Posts |
Posted - 2010-08-05 : 12:50:52
|
When i tried this SELECT SERVERPROPERTY ('InstanceName') AS MyServerName, i received my instance database name (4C05147D-CB87-40), and then i tried to use this to get my database:srvName - RICARDO-PC\4C05147D-CB87-40Server svr = new Server(@"" + srvName + "");foreach (Database dbServer in svr.Databases){cbServers.Items.Add(dbServer.Name);}but i get this error:error: 40 - One error occour with the instance trying to conect to the SQL serverVerify if the instance name is correctAnd if i use this SELECT [name] FROM sys.databasesI received all my databases names, but if i tried to make a backup of the one i want i get the error:System.Data.SqlClient.SqlError: Could not locate entry in sysdatabases for database <databaseName> No entry found with that name. Make sure that the name is entered correctly.But i can make a backup of this databases master,model, msdb.Why System don't recognize my databases? Just recognize system database(master,model, msdb, dbtemp) |
|
|
|
|
|
|
|