List of Databases from SQL Server

Write now my connection string is like so:
con.ConnectionString = @"Server=servername;Database=DatabaseName;Trusted_Connection=True;";
I am trying to make my program a bit more "interactive" so the user can choose which database within the server to view in the datagridview (along with the list of tables).
Am I supposed to remove the Database=DatabaseName portion of my connection string, and then the query "select * from master.dbo.sysdatabases" to get the list of Databases available? Would "select * from master.dbo.systables" give me a
list of tables within any specific database?
Thanks in advance.
-Nothing to see. Move along.

Thanks for the answer. With your help I successfuly integrated comboboxes to select the database and the related tables for each. Here is the code:
private void Form1_Load(object sender, EventArgs e)
{ loadConstructor(); }
//user selects an item in the Database combobox
private void cbx_Databases_SelectedIndexChanged(object sender, EventArgs e)
{ cbxDatabaseChange(); }
private void loadConstructor()
setPermissions();
con.ConnectionString = @"Server=serverName; Trusted_Connection=True;";
getDatabaseList();
private void setPermissions()
//DGV is read only!
dataGridView1.AllowUserToAddRows = false;
dataGridView1.AllowUserToDeleteRows = false;
dataGridView1.EditMode = DataGridViewEditMode.EditProgrammatically;
private void getDatabaseList()
//Get the list of databases from the server
cmd.Connection = con; cmd.CommandText = "select * from master.sys.sysdatabases;";
try
con.Open();
dataReader = cmd.ExecuteReader();
dataReader.Read();
if (dataReader.HasRows)
while (dataReader.Read())
{ cbx_Databases.Items.Add(dataReader.GetString(0)); }
else
{ MessageBox.Show("No databases found in the following connection string: '" + con + "'"); }
con.Close();
catch (Exception ex)
{ MessageBox.Show("Someone set us up the bomb! " + ex.ToString()); }
if (cbx_Databases.Items.Count > 0)
{ cbx_Databases.SelectedIndex = 0; }
private void cbxDatabaseChange()
//Now that we know the name of the database (user selected in combobox)
//Change the connection string accordingly
setConString(cbx_Databases.SelectedItem.ToString());
//get the tables using the new connection string
getTableNames();
//change the connection string to include the database name (string db)
private void setConString(string db)
{ con.ConnectionString = @"Server=serverName; Database=" + db + "; Trusted_Connection=True;"; }
private void getTableNames()
cbx_Tables.Items.Clear();
cmd.Connection = con; cmd.CommandText = "select * from " + cbx_Databases.Text + ".sys.tables;";
try
con.Open();
dataReader = cmd.ExecuteReader();
dataReader.Read();
if (dataReader.HasRows)
while (dataReader.Read())
{ cbx_Tables.Items.Add(dataReader.GetString(0)); }
con.Close();
if (cbx_Tables.Items.Count > 0)
cbx_Tables.Enabled = true;
cbx_Tables.SelectedIndex = 0;
catch (Exception ex)
{ MessageBox.Show("Someone set us up the bomb! " + ex.ToString()); }
if (cbx_Tables.Items.Count > 0)
{ cbx_Tables.SelectedIndex = 0; }

Similar Messages

  • How to Migrate my database from SQL Server 2000 to Oracle

    I want to transfer my database from SQL Server 2000 to Oracle, Can I do this without using Oracle Migration Workbench ??
    Please help me.
    Thanks in advance
    Vicky... :-)

    Do you have a good technical reason for not wanting to use the Migration Workbench?
    Given that it's free and does a hell of a lot of the work for you, why wouldn't you use it?
    Other than that, I would say you would be on your own...
    cheers,
    Anthony

  • I want to query oracle database from sql server can anyone tell steps 2 fo

    i want to query oracle database from sql server can anyone tell steps 2 followed
    i tried with linked servers but it is throwing errors can anyone hepl in this regard
    The operation could not be performed because the OLE DB provider 'MSDAORA' was unable to begin a distributed transaction.
    OLE DB error trace [OLE/DB Provider 'MSDAORA' ITransactionJoin::JoinTransaction returned 0x8004d01b].

    First of all - you are in the wrong forum.
    Look either for the Database general or search for Transparant / Heterogenous Gateways.
    cu
    Andreas

  • I want to query oracle database from sql server can anyone tell steps 2 fol

    i want to query oracle database from sql server can anyone tell steps 2 followed
    i tried with linked servers but it is throwing errors can anyone hepl in this regard
    The operation could not be performed because the OLE DB provider 'MSDAORA' was unable to begin a distributed transaction.
    OLE DB error trace [OLE/DB Provider 'MSDAORA' ITransactionJoin::JoinTransaction returned 0x8004d01b].

    First of all - you are in the wrong forum.
    Look either for the Database general or search for Transparant / Heterogenous Gateways.
    cu
    Andreas

  • Importing Database from SQL Server into Oracle 8i

    Hello Friends,
    Cuurentlly we are using SQL Server as our application database, Now we want to switch on at Oracle 8i,bcz of some problems,
    If anybody had done so,then please help me in solving this problem,
    I wana Import whole database from SQL server to Oracle
    Lot of thanks

    Hi,
    Use the SQL Server Enterprise Manager to export all the tables from SQL to oralce.
    When selecting the target database use the Oracle native driver (the name is not on top of my head) and not the ODBC one.
    You will have problems with datatypes. Make sure to edit the mappings for the proper datatype if required.
    If you have ntext columns, make sure they are translated to CLOB and not long.
    Regards,
    Wasim.

  • Is it possible to transfer a database from SQL Server 2012 to SQL Server Express 2012?

    Is it possible to transfer a database from SQL Server 2012 to
    SQL Server Express 2012? Ideally I would like to backup the database from SQL Server 2012 and restore it on SQL Server Express 2012. Is that possible?

    Is it possible to transfer a database from SQL Server 2012 to
    SQL Server Express 2012? Ideally I would like to backup the database from SQL Server 2012 and restore it on SQL Server Express 2012. Is that possible?
    Yes it is possible but database size should not be greater than 10 G as max databse size supported for Express 2012 is 10 G
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers

  • Can you replicate databases from SQL Server 2014 Enterprise Edition to SQL Server 2014 Standard edition?

    Hello,
    Can you replicate databases from SQL Server 2014 Enterprise Edition to SQL Server 2014 Standard edition? 
    Thanks. 

    Yes, you can replicate from Enterprise edition to Standard edition.  The only caveat is Peer-to-Peer Replication requires all nodes to be Enterprise Edition.
    Brandon Williams (blog |
    linkedin)

  • Cannot connect to Oracle 11gR2 database from SQL Server 2005

    Both SQL Server (Windows) and Oracle (Linux) are in 64bit environments.
    I have done the following on a Windows 2008 R2 with SQL Server 2005:
    Install InstantClient from Oracle Database 11g Release 2 Client (11.2.0.1.0) for Microsoft Windows (x64) to C:\Oracle
    Install oledb from 64-bit ODAC 11.2 Release 3 (11.2.0.2.1) for Windows x64 by executing install.bat oledb c:\oracle odac
    Note: Not sure whether 11.2.0.2.1 version of ODAC will cause any problem since I cannot find 11.2.0.1.0 version.
    I have checked the Allow inprocess of OraOLEDB.Oracle provider in SSMS.
    I have executed sp_addlinkedserver @server = 'ORACLE_TEST', @srvproduct = 'Oracle', @provider = 'OraOLEDB.Oracle', @datasrc = '##.##.##.##:1521/TEST'
    The ##.##.##.## is the ip address of the Linux server which has the Oracle 11gR2 database TEST.
    I have executed sp_addlinkedsrvlogin @rmtsrvname = 'ORACLE_TEST', @useself = 'FALSE', @rmtuser = 'xxxx', @rmtpassword = 'yyyy'
    The xxxx is the oracle username and yyyy is the password for the oracle user xxxx.
    I know the oracle database TEST is up since I have setup connection in Oracle SQL Developer having:
    ##.##.##.## as the hostname
    1521 as the Port
    xxxx as the username
    yyyy as the password
    TEST as the service name
    When I click Test Connection for the linked server ORACLE_TEST in SSMS, it just hang.
    When I issue a query like select count(*) from oracle_test..xxxx.table1, it just run forever. I'm not so sure how to query an oracle table. I have also tried select count(*) from oracle_test.xxxx.xxxx.table1.
    When I retype the password in the Linked Server Properties, it just run forever.
    Do I need to create a tnsnames.ora on the Windows machine?
    Do I need to change the tnsnames.ora on Linux machine?
    I'm very new to Oracle.

    This forum is dealing with connections from an Oracle database to SQL Server - so the Oracle database is the driving site and this is the way round from your linked server set up.
    As you're suing the instant client you might post your issue in the instant client forum:
    Instant Client

  • Remove Deteled Databases from SQL Server Management Studio List

    Hi,
        I am using SQL Server Express 2008 Management Studio & in the databases list are some databases that are non existent (have been deleted in Windows Explorer). How do I remove them as trying to delete when logging in using Windows authentication
    fails?
    Thanks
    Paul.
    Paul Wainwright

    Hi pr_wainwright,
    I’m writing to follow up with you on this post. Was the problem resolved after performing our action plan steps? According to your description and error message, we need to verify if your windows login account has sysadmin permission. The error 3701 occurs
    when you use an account to execute the script who has not grant the permission about modifying database properties and creating database. I do a test, when the SQL Server Service is stop, I delete the data and log file of database from Windows Explorer, then
    restart the service again, and connect to the SQL Server instance via windows login account which is sysadmin role. In SSMS list, you can right click the database and choose “ delete” option. Or you also use the drop statement by using master database first.
    and two ways can all run well.
    Regards,
    Sofiya Li
    If you have any feedback on our support, please click here.
    Sofiya Li
    TechNet Community Support

  • Moving databases from SQL Server 2012 to SQL Server 2014

    Hi
    I need to move all my SP 2013 databases from a SQL Server 2012 to a SQL Server 2014. I have read these articles:
    http://technet.microsoft.com/en-us/library/cc512725(v=office.15).aspx
    http://sharepointpromag.com/sharepoint-administration/simple-guide-moving-sharepoint-content-databases-new-server
    The TechNet article says:
    The new database server must run either the same version of Windows Server and SQL Server as the existing database server or one of the following versions:
    SQL Server 2008
    SQL Server 2012
    SQL Server 2014
    And the article in SharePoint Pro Magazine says:
    Obviously you’ll need your target SQL server (or instance) installed and configured. It should use the same version and patch level of SQL Server as the source SQL server
    So I'm a bit confused. Which article is right?
    Thanks
    Jakob

    it is fully supported and a simple process to move to a new sql server (anything 2008+ works).  just don't go back in versions.  you can go 2008-2012, 2008-2014, 20120-2014, just not 2012-2008, etc.
    just be sure not to detach/attach the databases in sql, do a sql database backup, then a sql database restore on the new server and point sharepoint (hopefully using aliases, as it makes this all much smoother) to point to the new server.
    Also, be sure to put SP1 and the April 2014 CU or newer on the farm BEFORE moving the databases.  2014 is "supported before the April CU, but there are several compatibility issues prior to april CU.  one example is that user profile sync doesn't
    work properly with sql 2014 if sharepoint is not at least april 2014 CU.
    hope that all is clear and helps you out, let me know if there are more questions.
    Christopher Webb | Microsoft Certified Master: SharePoint 2010 | Microsoft Certified Solutions Master: SharePoint Charter | Microsoft Certified Trainer| http://tealsk12.org Volunteer Teacher | http://christophermichaelwebb.com

  • Issue in rebuilding index after restoring database from sql server 2005 to 2012

    Hi All,
    We have recently restored a database named DBA_admin from our sql server 2005 instance to sql server 2012 and we have added the database to out weekly maintenance plan. After adding the database to maintenance plan the job is failing every weekend due to
    below error message.
    Error message from maintenance plan history:
    Executing the query "ALTER INDEX [PK_lsttype] ON [dbo].[lstAssign..." failed with the following error: "Invalid object name 'admin.dbo.databaselog'.
      ALTER_INDEX - dbo.PK_lsttype". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
    Below is the code within the maintenance plan which the rebuild index task is using for database dba_admin:
    USE [dba_admin]
    GO
    ALTER INDEX [PK_lstType] ON [dbo].[lstType] REBUILD PARTITION = ALL WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 98, DATA_COMPRESSION = PAGE)
    Please let me know if any one knows how to fix this issue.
    Thanks in Advance.

    Sorry for the confusion.
    Here is what is happening.
    The query is failing while trying to rebuild index [Pk_lsttype] on table [lstAssign], both these objects belong to database
    admin.
    I have verified the old instance there is table databaselog within the database
    dba_admin, but in new SQL instance within the database dba_admin the table is not present.
    Even I'm not sure of what this table databaselog has to do with rebuilding indexes on table
    lstAssign within the admin database.
    I have manually tried to execute the alter index command within the database
    admin and it is failing with the below error.
    ALTER_TABLE - dbo.Query_pnb_sms
    Msg 208, Level 16, State 1, Procedure ddlDatabaseTriggerLog, Line 39
    Invalid object name 'dba_admin.dbo.databaselog'.

  • Backup Database From SQL Server 2014 with expired trial period.

    Hi,
    Looking for some advice. I created a database on a SQL Server 2014 Trial Version i downloaded from the Microsoft website. Our company bought a license for SQL Server 2012 instead of 2014, how can i migrate my database to 2012 without the ability to connect
    to my 2014 Server or Management studio (Because the trial period has expired)?
    Thank You.

    Hi,
    Alternatively, you can stop SQL Services and then locate the mdf & ldf file copy these files to new location.
    Now you try to attach above files in new server.
    Sorry little correction
    I dint pay attention to 2014 to 2012, in this case you need to attach these files on SQL Server 2014 then generate script and execute these script on 2012.
    Please refer following article on how to attach database.
    Attach a Database
    Also refer following post with similar issue.
    MS SQL 2008 Evaluation expired...need to get database backup
    Please mark solved if I've answered your question, vote for it as helpful to help other users find a solution quicker
    Praveen Dsa | MCITP - Database Administrator 2008 |
    My Blog | My Page

  • Migration of a database from sql server 2008 r2 to oracle 11 g

    We're trying to migrate a Sql server managment studio database to Oracle 11g using SQL Developer 4.0. We can successfully connect to both Sql server managment studion 8.0 and Oracle 11g using the tool, as well as click through the Migration Wizard and start the migration.
    This opens the Database Migration dialog box, which indicates the capture process starts normally. we get the following error:
    ora :01440 : can not insert null into migrlog (id column) ,
    \and then after some time , i get an error that migration failed
    I know , that we vcan nt insert null into migrlog table , then pls tell me how can  i resolve fro this problem  . is there any way to solve it,
    i am not getting the reason,I thing it may be due to reason that , I have table's column in my source db with more than 30 character.
    If i am migrating one by one table . then it is not giving any error, and identifier name is getting shrink in 30 character. but i am not getting the view , stored procedure , indexes , and others
    then what is the solution  for that, somebody pls suggest any help?????????????

    This forum is dealing with Oracle gateway connecting to a foreign database. When connecting with SQL Server LINKED Server mechanism to Oracle you're using the Oracle OLEDB driver and there's a separate thread that assist you with the Oracle OLEDB driver. Please close this thread and post your issue in this forum:
    Oracle Provider for OLE DB

  • Cannot connect to Oracle database from SQL Server

    Hi
    We have set up a SQL Server linked server and tried to use this SQL Server linked server to connect to Oracle database. We are using SQL Server 2008 and Oracle client 11g 11.02.00.01. However, we got this error message:
    Msg 7347, Level 16, State 1, Line 1
    OLE DB provider 'OraOLEDB.Oracle' for linked server 'OurLinkedServer' returned data that does not match expected data length for column '[OraOLEDB.Oracle].Ourfieldname'. The (maximum) expected data length is 6, while the returned data length is 2.
    We are able to connect some of the tables ok but some of the tables are not connected and got the above error message.
    Any suggestions are greatly appreciated.
    Thanks a lot
    Tom

    Hi
    Here is more information. We just found out that the Oracle database team changed the character set to something else and then they changed it back to UTF8.
    Currently, it is using UTF8 character set on the Oracle side. Will this causing us this error message on our sql server linked server?
    The error message said "The (maximum) expected data length is 6, while the returned data length is 2."
    This refers to a field/column with char(1)
    Any suggestions are greatly appreciated
    Thank you
    Tom

  • Siebel database migration from Sql Server 2005 to Oracle 11g RAC.

    Hi,
    We would like to migrate our Siebel database from Sql Server 2005 to Oracle 11g RAC. Can you suggest the best way to do that ?
    The current configurations are:
    Application : Siebel
    database : SQL Server 2005
    The hardware can be changed if needed. Can you please suggest the best approach ?
    Thanks,
    Naveen.
    Edited by: Naveen Kumar C on Mar 18, 2011 9:10 PM
    Edited by: Naveen Kumar C on Mar 18, 2011 11:44 PM

    Hi Naveen,
    We would like to migrate our Siebel database from Sql Server 2005 to Oracle 11g RAC. Can you suggest the best way to do that ?You will need much more which suggestions.
    You will need a Siebel professional which has done this type of migration. Migrating the Database is not a task so hard, after migrating your environment should be functional and healthy it is usually the task problematic.
    The hardware can be changed if needed. Can you please suggest the best approach ?We can recommend the minimum recommended, but this documentation already does, you need to do a analysis on your environment and ask a vendor Siebel tell the which is recommended for you and how to find the best "number" for you, in your case is very hard because everything changes.
    Check this Step-by-Step
    Migrating a Microsoft SQL Server Database to Oracle Database 11g
    http://st-curriculum.oracle.com/obe/db/hol08/sqldev_migration/mssqlserver/migrate_microsoft_sqlserver_otn.htm
    Regards,
    Levi Pereira

Maybe you are looking for

  • How to print the content of a textarea in java?

    Hello, i'm currently developping a HTML Editor in java but i've got a problem with printing job... Does anyone know a simple code to print the content of a textarea by clicking on a button? for instance: JTextarea textarea = new JTextArea(); JButton

  • Erase data from open hub destination data service

    Hi, I'm getting an error trying to delete data from a cube, for which data are extracted using open hub service and loaded into a table. The error given is the following: Request updated in 1794 already by 1795 target DTPR_4EEX9CGGXLTU2QIPWUAIEUDZK D

  • Failure to install Windows XP Mode under Win7

    After (apparently successful) installation of 500-megabyte "Windows XP Mode," installation of 10-megabyte "Windows Virtual PC," after reboot, reports "Failure configuring Windows updates / Reverting changes." Event viewer shows "Package KB958559 fail

  • Unable to assemble book

    I have built a book in iPhoto, but cannot place the order for it, because I keep getting the following error message when the system tries to assemble the book: file://localhost/Users/strandoutdoors/Desktop/Screen%20shot%202012-02-04%20at%20 9.31.46%

  • Multiple addressees in mail

    I sent an e-mail thru mail in Snow Leopard using my MobileMe account to 3 addressees all in the "To" section.  After I sent it I checked my sent messages and it only showed that it was sent to the first addressee on the list.  Did I do something wron