Populating Swing JList using SQL Database

Sup peeps, im trying to to populate a JList using the entries in a table in a database i created.
package networks;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.PrintWriter;
import java.sql.*;
public class Contestantlist extends javax.swing.JFrame {
    /** Creates new form contestantList */
    public Contestantlist() {
        initComponents();
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {
         try
           // Load driver's class, inilialize, register with DriverManager
           //Class.forName("oracle.jdbc.driver.OracleDriver");
           Class.forName("org.gjt.mm.mysql.Driver");
        catch (ClassNotFoundException e)
           System.out.println("Unable to load driver class");
           return;
        ResultSet rs = null;
        try
           // Call DriverManager's methods (all are static)
           // To print log on sysout
           //DriverManager.setLogStream(System.out); //JDBC 1.x driver
          // DriverManager.setLogWriter(new PrintWriter(System.out) );
           // Connect to database.  DriverManager loads each registered driver
           // in turn until one can handle the database URL format
           //Connection con = DriverManager.getConnection(
           //                     "jdbc:oracle:thin:@host.domain.com:1521:db_name"
           //                     ,"scott","tiger");
          // Connection con = DriverManager.getConnection("jdbc:mySql://localhost:3306/Contest","root","blink182");
           // Get the DatabaseMetaData object to display database info
        //   DatabaseMetaData dmd = con.getMetaData();
         //  Statement stmt = con.createStatement();
       //     String sql;
         //  sql = "SELECT Username FROM Contestant WHERE Username IS NOT NULL";
          // rs = stmt.executeQuery(sql); //throws SQLExecption if fails
          // printResultSet(rs);
           DriverManager.setLogWriter(new PrintWriter(System.out) );
           Connection con = DriverManager.getConnection("jdbc:mySql://localhost:3306/Contest","root","blink182");
           // Get the DatabaseMetaData object to display database info
           DatabaseMetaData dmd = con.getMetaData();
           String sql;
             Statement stmt = con.createStatement();
         sql = "SELECT Username FROM Contestant WHERE Username IS NOT NULL";
         rs = stmt.executeQuery(sql); //throws SQLExecption if fails
        ResultSetMetaData rsmd = rs.getMetaData();
        int numCols = rsmd.getColumnCount();*
        // Display data, fetching until end of the result set
        // Calling next moves to first or next row and returns true if success
        while(rs.next() )
           // Each rs after next() contains next rows data
           for(final int i=1; i<=numCols; i++)
              if(i > 1) System.out.print(",");
              // Almost all SQL types can be cast to a string by JDBC
             // System.out.print(rs.getString(i));
              theList.setModel(new javax.swing.AbstractListModel() {
                  String[] strings = { rs.getString(i) };
                  public int getSize() { return strings.length; }
                  public Object getElementAt(int i) { return rs.getString(i); }
           System.out.println("");
        catch(Exception f)
        titleLabel = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
       // theList.setVisibleRowCount(6);
        theList = new javax.swing.JList();
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        titleLabel.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        titleLabel.setText("The Scrupulous Contestants!");
       /* theList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 3", "Item 4", "Item 5", "Item 4", "Item 5"  };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings; }
jScrollPane1.setViewportView(theList);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(70, 70, 70)
.addComponent(titleLabel))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(71, Short.MAX_VALUE))
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(titleLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(124, Short.MAX_VALUE))
pack();
}// </editor-fold>
/* private static void printResultSet(ResultSet rs) throws SQLException
     DriverManager.setLogWriter(new PrintWriter(System.out) );
Connection con = DriverManager.getConnection("jdbc:mySql://localhost:3306/Contest","root","blink182");
// Get the DatabaseMetaData object to display database info
DatabaseMetaData dmd = con.getMetaData();
String sql;
     Statement stmt = con.createStatement();
sql = "SELECT Username FROM Contestant WHERE Username IS NOT NULL";
rs = stmt.executeQuery(sql); //throws SQLExecption if fails
ResultSetMetaData rsmd = rs.getMetaData();
int numCols = rsmd.getColumnCount();
// Display data, fetching until end of the result set
// Calling next moves to first or next row and returns true if success
while(rs.next() )
// Each rs after next() contains next rows data
for(int i=1; i<=numCols; i++)
if(i > 1) System.out.print(",");
// Almost all SQL types can be cast to a string by JDBC
System.out.print(rs.getString(i));
System.out.println("");
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Contestantlist().setVisible(true);
// Variables declaration - do not modify
private javax.swing.JList theList;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel titleLabel;
// End of variables declaration
I can tell that im not using something correctly. Can you guys just point out how i should proceed through this? I encapsulated the piece of code that has got me confused.
Edited by: 860597 on May 29, 2011 6:29 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

package networks;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.PrintWriter;
import java.sql.*;
public class Contestantlist extends javax.swing.JFrame {
    public Contestantlist() {
        initComponents();
    @SuppressWarnings("unchecked")
    private void initComponents() {
         try
           Class.forName("org.gjt.mm.mysql.Driver");
        catch (ClassNotFoundException e)
           System.out.println("Unable to load driver class");
           return;
        try
             ResultSet rs = null;
           DriverManager.setLogWriter(new PrintWriter(System.out) );
           Connection con = DriverManager.getConnection("jdbc:mySql://localhost:3306/Contest","root","blink182");
           DatabaseMetaData dmd = con.getMetaData();
           String sql;
             Statement stmt = con.createStatement();
         sql = "SELECT Username FROM Contestant WHERE Username IS NOT NULL";
         rs = stmt.executeQuery(sql);
         printResultSet(rs);
        ResultSetMetaData rsmd = rs.getMetaData();
        int numCols = rsmd.getColumnCount();
        catch(Exception f)
        titleLabel = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        titleLabel.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        titleLabel.setText("The Scrupulous Contestants!");
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
        jScrollPane2.setViewportView(jTable1);
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, 0)
                        .addComponent(titleLabel))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, 0)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 454, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(33, Short.MAX_VALUE))
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(titleLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(263, Short.MAX_VALUE))
        pack();
    }// </editor-fold>/ </editor-fold>
    private static void printResultSet(ResultSet rs) throws SQLException
           DriverManager.setLogWriter(new PrintWriter(System.out) );
          Connection con = DriverManager.getConnection("jdbc:mySql://localhost:3306/Contest","root","blink182");
          DatabaseMetaData dmd = con.getMetaData();
          String sql;
            Statement stmt = con.createStatement();
        sql = "SELECT Username FROM Contestant WHERE Username IS NOT NULL";
        rs = stmt.executeQuery(sql); //throws SQLExecption if fails
       ResultSetMetaData rsmd = rs.getMetaData();
       int numCols = rsmd.getColumnCount();
       while(rs.next() )
          for(int i=1; i<=numCols; i++)
             if(i > 1) System.out.print(",");
             System.out.print(rs.getString(i));
          System.out.println("");
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Contestantlist().setVisible(true);
    private javax.swing.JList theList;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel titleLabel;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
}I have amended the code and now it does print out the specified contents of my table.
I have added a a JTable, but excuse my ignorance because i have no idea as to how to proceed from here. I can't figure out how call database entries from the array in the JTable.
Edited by: 860597 on May 29, 2011 7:27 AM

Similar Messages

  • Got an error while creating bind variables using sql database.

    iam going to use sql database for ADF-BC .
    i created the bind variable and apply the bind position for the corresponding variable in the view object editor.when i click test it shows me "query is valid". when i tried to run that it gives me two errors.
    1) sql error during statement preparation.(ie) select empid ,empname......from the emptable where empid like :'emp' and
    2) [Microsoft][SQl server  2000 driver  for jDBC] invalid parameter bindings
    i need help to know the solution for this...(or) is there any other way to create bind variable ......

    The 3 binding styles supported by JDev:
    Oracle Named - ie. SELECT xxxx FROM xxxx WHERE emp_id = :vEmp (note colon and variable name)
    Oracle Positional - ie SELECT xxxx FROM xxxx WHERE emp_id = :1 (note colon)
    JDBC Positional - ie SELECT xxxx FROM xxxx WHERE emp_id = ?
    Literally this query is sent to the database to execute, then the bind variables values are applied as a separate database operation. If SQL Server doesn't suport any of these binding styles, it's not going to work. As Chris Noonan suggests, try the JDBC Positional style though as you're using a JDBC driver to connect to SQL Server and it should support that style (the others are Oracle styles), and make sure you've switched the binding style on the VO query page to "JDBC Positional" too.
    You must also on the VO bind variable page define your bind variables.
    Also read the 10.1.3 JDev guide on ADF Business Components and View Object bind variables.
    CM.

  • How to find out what is populating a table using sql

    I would like to find out what is populating a particular tabe. I used
    select name,type from dba_source where text like upper('%some_table%'). I know this will give me procedure,function package etc, If this table is being populated by a form how will i get the form name. I am using window XP oracle 10G database

    IF you to check what is running at a precisly momemmt you need to Join :
    v$transaction a, Gives you current Transaction going On
    v$session b, Gives You info about session User
    v$sql c Gives you info about SQL Running at Precisly momment
    With these Condition you are able to Find what's is Runnimg
    where a.SES_ADDR= b.SADDR (+) and
    b.SQL_HASH_VALUE = c.HASH_VALUE(+)
    I Hope This May help.
    Rgds

  • Primary key population through sequence using SQL loader

    Hi Experts,
    Is it possible to populate primary key column using a sequence while trying to load the data through SQL loader?
    Requirement is like that..
    Flat file contains 4 fields and I need to populate 5th Column which will be primary key and will be from one sequence available in database.
    Regards,
    SKP

    http://download.oracle.com/docs/cd/B19306_01/server.102/b14215/ldr_field_list.htm#sthref1274
    Alternatively, you could load data, then populate the required column with unique values using sequence and then add primary key constraint.

  • Is it possible using SQLite to collect data from an older SQL database?

    Is it possible using SQLite to collect data from an older SQL database? Where can I find a possible answer. Thanks in advance.

    There are 3rd-party tools (see comprehensive list at http://www.kenhamady.com/bookmarks.html) that provide extra pdf functionality on top of the pdf export from Crystal. 
    In the case of my Visual CUT software, you can use hidden formulas inside your Crystal report to generate form fields (pre-populated as well as empty) as part of the pdf export process.
    hth,
    ido

  • Can we use different Databases (Oracle & SQL Server) in one report?

    Post Author: venki5star
    CA Forum: .NET
    Hi there.
    Can we use different databases (Oracle & SQL Server) in a same report?
    If possible how?
    Another question,
    Can we change the Provider Name at runtime of the given report. If so the above question is useless...
    Thanks in Advance.

    I tried this using Oracle Provider for OLEDB (the one that supplied by Oracle Client) and Crystal Reports 9. you can drag the column into designer but the image does not appear in preview.
    I guess it's because CR does not recognized it as image, and there are no information that the blob data is an image at all.

  • Is it possible to save / extract data from a MS SQL database 2008 using lookout 6.2?

    Is it possible to save / extract data from a MS SQL database 2008 using lookout 6.2?
      Now a days we are saving / extracting data in a excel spreadsheet, but we would like to do that using a database because it is better.

    You can use ODBC connection to work with SQL Server database.
    Use SQLExec object to execute the SQL statement. Here is a KB about the SQL statement.
    http://digital.ni.com/public.nsf/allkb/4ADEEA04CD24AE0B862565E20002A16F?OpenDocument
    To write data to spreadsheet is more straightforward because Lookout has built-in spreadsheet object. But you need to write SQL statement by yourself to interact with other database.
    To read the data back is the same way. Just use "select" SQL statement to query. You can use Datatable object to query.
    The "Data Source" can be "DSN = data source name;". The data source name is configured in Control Panel->Administrative Tools->Data Sources(ODBC).
    Ryan Shi
    National Instruments

  • Not able to access database from a remote machine using SQL Server Management Studio

    Hi,
    I have a DB_BOX with SQL Server 2008 R2 installed. I can access the databases on the local machine using SQL Server Management Studio but it is not accessible from other machines, though the machines are in same domain.
    I have remote enabled on SQL Server box, TCP enabled, firewall off. I checked with IP Address too, all SQL Server services are running.
    The SQL Server log shows the message
    The requested service has been stopped or disabled and is unavailable at this time. The connection has been closed.
    I get the below message in SSMS from remote machine.
    Details of error message are
    ===================================
    Cannot connect to DB_BOX.
    ===================================
    A connection was successfully established with the server, but then an error occurred during the login process. (provider: TCP Provider, error: 0 - The specified network name is no longer available.) (.Net SqlClient Data Provider)
    For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=64&LinkId=20476
    Server Name: DB_BOX
    Error Number: 64
    Severity: 20
    State: 0
    Program Location:
       at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
       at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
       at System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error)
       at System.Data.SqlClient.TdsParserStateObject.ReadSni(DbAsyncResult asyncResult, TdsParserStateObject stateObj)
       at System.Data.SqlClient.TdsParserStateObject.ReadNetworkPacket()
       at System.Data.SqlClient.TdsParserStateObject.ReadBuffer()
       at System.Data.SqlClient.TdsParserStateObject.ReadByte()
       at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
       at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
       at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
       at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
       at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
       at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
       at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
       at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
       at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
       at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
       at System.Data.SqlClient.SqlConnection.Open()
       at Microsoft.SqlServer.Management.SqlStudio.Explorer.ObjectExplorerService.ValidateConnection(UIConnectionInfo ci, IServerType server)
       at Microsoft.SqlServer.Management.UI.ConnectionDlg.Connector.ConnectionThreadUser()

    Sorry, missed the message from the errorlog in the original post. You shouldn't have included that big .Net dump that hid the important facts. :-)
    My first Google attempt on that message (which I have never seen before) suggests that the TCP Enpoint is stopped, so try this:
    ALTER ENDPOINT [TSQL Default TCP]
    STATE=STARTED;
    Erland Sommarskog, SQL Server MVP, [email protected]
    This solves the problem. Thanks...

  • How can i configure an odbc using a database from sql to my excel

    Hi, i hope you can help me
    I have an excel sheet in wich i'm working, but i need to import data from a database used SQL, but i need the ODBC connection,... I try to used the administrator ODBC, but it has no driver for me to connect it to the SQL database, ... who knows wich tool can i use?
    best regards,
    Pamela

    As far as I know -you still can't do that with the mail app on a device. You can select each contact by tapping the blue + sign to open the contacts app and you have to add them one at a time.
    These are third party apps that will let you do this - Group Email ... And there are others in the app store.

  • Can't connect to SQL Database using new login

    I can connect to Azure SQL Database using the admin ID created when I set up the Azure account.  Now I want to set up a different login that has only regular read/write privileges.  I have followed the instructions on several web posts, to create
    a login at the server level, then create a user at the database level from the login.  When I try to connect, though, the connection fails.  I get an error message, and a GUID that I am supposed to supply to MS tech support, except that all I have
    is a standard Azure subscription, which does not include tech support.
    Here is what I have done so far:
    Logging in to the server with the admin account with SQL Mgmt Studio, I go to the master database on my Azure server, and create the login:
    CREATE LOGIN clouduser@gxw8x04nlb with PASSWORD = 'xoxoxoxo';
    This appears to work (password supplied is a "strong" password), or at least it doesn't show any error response.
    Then, connecting to the production database in Azure, I set up a user and set permissions as follow:
    CREATE USER clouduser1 FROM LOGIN clouduser@gxw8x04nlb;
    EXEC sp_addrolemember 'db_datareader', 'clouduser1'
    EXEC sp_addrolemember 'db_datawriter', 'clouduser1'
    When I attempt to connect to Azure using the new login, however, I get an error message (from SQL Mgmt Studio as well as from MS Access).  I am using the SQL Server Native Client 10.0.
    The message is:
    Connection failed:
    SQLState '28000'
    SQL Server Error 18456
    [Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user 'clouduser'.
    Connection failed:
    SQLState: '01000'
    SQL Server Error: 40608
    [Microsoft][SQL Server Native Client 10.0][SQL Server]This session has been assigned a tracing ID of
    '271851d5-8e94-497c-a332-d9d40682bb7a'.  Provide this tracing ID to customer support when you need assistance.
    Is there some missing step I need to do, to permit the login to see the database?  I have looked for such in the various discussions about connection problems, but have not been able to find such a thing.   Or extend more permissions to the new
    user? Or specify a default user ID for a given login ?  (as they do not have the same names, in the examples I have seen).  I tried making the user ID the same as the login (w/o the server name), but that didn't seem to help, either.
    I have done numerous web searches, and tried about every variation of login or user ID, password, etc. that I can think of, and all of them encounter the same error.  It's got to be something very simple - clearly Azure supports more than one login
    per database.  But's that's all I have at the moment.  That login connects just fine, but others won't, using the same PC, middleware, IP address, etc.
    Any help would be much appreciated -
    Thanks,
         Doug

    Olaf -
    I noticed that, but all of the examples I have seen have Users named slightly differently from the Logins.  I did try logging in with the Login name instead.  No good.  I tried making the Login and the User name the same (clouduser).  Also
    no good - same symptoms.
    I think the problem is that the initial creation of the Login needs to be done WITHOUT the server name on the end.  
    Logged in to the master DB, I tried:  Create LOGIN clouduser@gxw8x04nlb with PASSWORD = 'xoxoxoxo';
    That didn't give me an error message, but I think it created a LOGIN of 'clouduser@gxw8x04nlb'.  When
    referenced from the outside world, I would need to specify 'clouduser@gxw8x04nlb@gxw8x04nlb'.
    I tried deleting the logins, and then creating the login 'clouduser' in the Master DB.  Then in
    the application DB, I created User clouduser from LOGIN clouduser, and then assigned a role.  That seems to work!
    In my connection string, File DSN, etc. I still need to supply the login as 'clouduser@gxw8x04nlb'.
     But when I am logged in to the server, and working in the Master DB or the application DB, I just refer to the Login as 'clouduser'.  
    Seems a little more complicated than it really should be, but at least I now have something that works.
    Doug
    Doug Hudson

  • Getting error while backing up SQL database using powershell

    I am trying to backup SQL database but strange thing is taking lpace, few databases i can backup with powershell but few i am getting error
        Exception calling "SqlBackup" with "1" argument(s): "Backup failed for Server 
        'Server1'. "
        At C:\_Scripts\defaultbackup.ps1:40 char:1
        + $smoBackup.SqlBackup($server)
        + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : FailedOperationException
        $dbToBackup = "test"
        #clear screen
        cls
        #load assemblies
        #note need to load SqlServer.SmoExtended to use SMO backup in SQL Server 2008
        #otherwise may get this error
        #Cannot find type [Microsoft.SqlServer.Management.Smo.Backup]: make sure
        #the assembly containing this type is loaded.
        [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null
        [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoExtended") | 
        Out-Null
        [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo") 
        | Out-Null
        [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoEnum") | Out-  
        Null
        #create a new server object
        $server = New-Object ("Microsoft.SqlServer.Management.Smo.Server") "(local)"
        $backupDirectory = $server.Settings.BackupDirectory
        "Default Backup Directory: " + $backupDirectory
        $db = $server.Databases[$dbToBackup]
         $dbName = $db.Name
         $timestamp = Get-Date -format yyyyMMddHHmmss
        $smoBackup = New-Object ("Microsoft.SqlServer.Management.Smo.Backup")
        #BackupActionType specifies the type of backup.
        #Options are Database, Files, Log
        #This belongs in Microsoft.SqlServer.SmoExtended assembly
        $smoBackup.Action = "Database"
        $smoBackup.BackupSetDescription = "Full Backup of " + $dbName
        $smoBackup.BackupSetName = $dbName + " Backup"
        $smoBackup.Database = $dbName
        $smoBackup.MediaDescription = "Disk"
        $smoBackup.Devices.AddDevice($backupDirectory + "\" + $dbName + "_" + $timestamp +   
        ".bak",   
        "File")
        $smoBackup.SqlBackup($server)
        #let's confirm, let's list list all backup files
        $directory = Get-ChildItem $backupDirectory
       $smoBackup.Devices.AddDevice($backupDirectory + "\" + $dbName + "_" + $timestamp + ".bak", "File")
    $smoBackup.SqlBackup($server)
    #let's confirm, let's list list all backup files
    $directory = Get-ChildItem $backupDirectory
    #list only files that end in .bak, assuming this is your convention for all backup files
        $backupFilesList = $directory | where {$_.extension -eq ".bak"}
        $backupFilesList | Format-Table Name, LastWriteTime
        $backupFilesList = $directory | where {$_.extension -eq ".bak"}
        $backupFilesList | Format-Table Name, LastWriteTime
    I read on internet that by using this in the script this problem can be sorted but i am
    not sure where exactly to put this line in above script set the ConnectionContext.StatementTimeout to 0
                  

    Hi Srk,
    I found the similar issue in this article, which had been sovled by adding the script below:
    $server = New-Object ("Microsoft.SqlServer.Management.Smo.Server") $dbInstance
    $server.ConnectionContext.StatementTimeout = 0
    Refer to:
    Exception calling "SqlBackup" with "1" argument(s)
    Please feel free to let me know if this method can not work.
    Best Regards,
    Anna Wang

  • How can I transfer a XML file content to a MS SQL database by stored procedure using LabWindows/CVI SQL Toolkit?

    Hi,
    I have a problem to transfer a XML file content to a MS SQL database by a given/fixed stored procedure. I'm able to transfer the content of the file by using following method ...
    hstmt = DBPrepareSQL (hdbc, EXEC usp_InsertReport '<Report> ..... </Report>');
    resCode = DBExecutePreparedSQL (hstmt);
    resCode = DBClosePreparedSQL (hstmt);
    ... but in this case I'm not able to fetch the return value of the stored procedure! 
    I have tried to follow the example of the stored procedure in the help documentation (DBPrepareSQL) but I miss a datatype for xml?!?
    Any idea how to solve my problem?
    KR Cake  
    Solved!
    Go to Solution.

    After some additional trials I found a solution by calling the stored procedure in this way
    DBSetAttributeDefault (hdbc, ATTR_DB_COMMAND_TYPE, DB_COMMAND_STORED_PROC);
    DBPrepareSQL (hdbc, "usp_InsertReport");
    DBCreateParamInt (hstmt, "", DB_PARAM_RETURN_VALUE, -1);
    DBCreateParamChar (hstmt, "XMLCONTENT", DB_PARAM_INPUT, sz_Buffer, (int) strlen(sz_Buffer) + 1 );
    DBExecutePreparedSQL (hstmt);
    DBClosePreparedSQL (hstmt);
    DBGetParamInt (hstmt, 1, &s32_TestId);
    where sz_Buffer is my xml file content and s32_TestID the return value of the stored procdure (usp_InsertReport(@XMLCONTENT XML))
    Now I face the problem, that DBCreateParamChar limits the buffer size to 8000 Bytes.
    Any idea to by-pass this shortage??

  • Can I use Other database as the repository, Sybase/SQL Server? Urgent!!!

    Hi all,
    Can I use Other database as the repository, Sybase/SQL Server? Urgent!!!
    And Can I use other database store business data and sync with lite?
    Thanks ahead!!!

    Jonathan,
    No, it is not possible to use any other database than Oracle (8.1.7) or later .
    Oracle Lite will only work with Oracle.
    Regards

  • How to store jpeg images in SQL server using NI database Connectivity Toolset. Can anyone please help me in this regard.

    Please tell how to store jpeg images in SQL Server using NI Database Connectivity Toolset.

    http://www.w3schools.com/sql/sql_datatypes.asp
    You setup a field as BLOB and store the binary of the picture there. Depending on the database it can be called differently as you can see in the link, in SQL server there's even a Image datatype.
    /Y
    LabVIEW 8.2 - 2014
    "Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
    G# - Free award winning reference based OOP for LV

  • From SharePoint Content Database, Using SQL-Server Query how to fetch the 'Document GUID' based on 'Content Type'

    I want to get all the documents based on content type using SQL Server Query. I know that, querying the content database without using API is not advisable, but still i want to perform this action through SQL Server Query. Can someone assist ?

    You're right, it's not advisable, may result in corruption of your databases and might impact performance and stability. But assuming you're happy to do that then it is possible.
    Before you go down that route, have you considered using something more safe like PowerShell? I've seen a script exactly like the one you describe and it would take far less time to do it through PS than it would through SQL.

Maybe you are looking for