Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Re-Mssql question

Re-Mssql question

Scheduled Pinned Locked Moved C / C++ / MFC
databasesql-serverhelpsysadminquestion
15 Posts 4 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M MsmVc

    it completes successfully but does not seem to make any change. After use database command then i check through this command.

    SELECT DB_NAME() AS DataBaseName

    it's always show "Master" database name.

    C Offline
    C Offline
    Code o mat
    wrote on last edited by
    #4

    Let's experiment, try this:

    CString udata="use \"databasename\"";
    //(databasename is like master ,use create database)
    Qry=spSQLServer->ExecuteWithResults((_bstr_t)udata,(LONG)udata.GetLength());

    > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <

    M 1 Reply Last reply
    0
    • C Code o mat

      Let's experiment, try this:

      CString udata="use \"databasename\"";
      //(databasename is like master ,use create database)
      Qry=spSQLServer->ExecuteWithResults((_bstr_t)udata,(LONG)udata.GetLength());

      > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <

      M Offline
      M Offline
      MsmVc
      wrote on last edited by
      #5

      thanks ,i use code which is given by you.But i got error

      Microsoft SQL-DMO (ODBC SQLState: 42000) Error: -2147221402 [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'databasename'. Invalid STDGMEDIUM structure

      C 1 Reply Last reply
      0
      • M MsmVc

        Hi All USE database command is not working for me.I was asking same question in last week but still i have no solution then i ask one more time.Plz help me connection code is here

        CString str1="",str2="",str3="";
        HRESULT hr;
        if SUCCEEDED(hr = CoInitialize(NULL))
        {
        try
        {

        		if (SUCCEEDED(spSQLServer.CreateInstance(\_\_uuidof(SQLServer2))))
        		{
        			try
        			{
        				HOST=(\_bstr\_t)m\_MHOST;
        			
        				if(rad1.GetCheck())
        				{
        					spSQLServer->LoginSecure = TRUE;
        					spSQLServer->Connect((\_bstr\_t)m\_MHOST);
        				}
        				else
        				{
        					spSQLServer->LoginSecure = FALSE;
        					spSQLServer->Connect((\_bstr\_t)m\_MHOST,(\_bstr\_t)m\_MUSR,(\_bstr\_t)m\_MPWD);
        				}
        				
        			
        				
        			
        			}
        			catch(\_com\_error pCE)
        			{
        			
        				str2.Format(\_T("%s"),
        				MessageBox(str2,"Message");
        				return TRUE;
        			}
        		}
        		else
        		{
        			str3.Format(\_T("Unable to create the SQL Server object.\\n"));
        	
        		}
        	}
        	catch(\_com\_error pCE)
        	{
        		str2.Format(\_T("\\n%s Error: %ld\\r\\n%s\\r\\n%s\\r\\n"),
        			(TCHAR\*)pCE.Source(),
        			pCE.Error(),
        			(TCHAR\*)pCE.Description(),
        			(TCHAR\*)pCE.ErrorMessage());
        	}
        
        
        }
        else
        {
        	str2.Format(\_T("Call to CoInitialize failed.\\n"));
        }
        

        Use database command code is here

        QueryResultsPtr Qry;
        _SQLServer2Ptr spSQLServer;
        CString udata="use 'databasename'";
        //(databasename is like master ,use create database)
        Qry=spSQLServer->ExecuteWithResults((_bstr_t)udata,(LONG)udata.GetLength());

        Select command is running fine like this

        CString sel="select * from 'Database name'.dbo.'Table Name'"
        Qry=spSQLServer->ExecuteWithResults((_bstr_t)sel,(LONG)sel.GetLength());

        Can any one help me why

        USE 'Database name'

        not working. Plz help me

        CPalliniC Offline
        CPalliniC Offline
        CPallini
        wrote on last edited by
        #6

        Your database's name is

        Database name

        ? :omg: in such a case, possibly you've to replace

        MsmVc wrote:

        CString udata="use 'databasename'";

        with

        CString udata="use 'Database name'";

        :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        In testa che avete, signor di Ceprano?

        M 1 Reply Last reply
        0
        • CPalliniC CPallini

          Your database's name is

          Database name

          ? :omg: in such a case, possibly you've to replace

          MsmVc wrote:

          CString udata="use 'databasename'";

          with

          CString udata="use 'Database name'";

          :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          M Offline
          M Offline
          MsmVc
          wrote on last edited by
          #7

          i always use like this

          CString udata="use 'Database name'";

          But still i have problem same.

          1 Reply Last reply
          0
          • M MsmVc

            Hi All USE database command is not working for me.I was asking same question in last week but still i have no solution then i ask one more time.Plz help me connection code is here

            CString str1="",str2="",str3="";
            HRESULT hr;
            if SUCCEEDED(hr = CoInitialize(NULL))
            {
            try
            {

            		if (SUCCEEDED(spSQLServer.CreateInstance(\_\_uuidof(SQLServer2))))
            		{
            			try
            			{
            				HOST=(\_bstr\_t)m\_MHOST;
            			
            				if(rad1.GetCheck())
            				{
            					spSQLServer->LoginSecure = TRUE;
            					spSQLServer->Connect((\_bstr\_t)m\_MHOST);
            				}
            				else
            				{
            					spSQLServer->LoginSecure = FALSE;
            					spSQLServer->Connect((\_bstr\_t)m\_MHOST,(\_bstr\_t)m\_MUSR,(\_bstr\_t)m\_MPWD);
            				}
            				
            			
            				
            			
            			}
            			catch(\_com\_error pCE)
            			{
            			
            				str2.Format(\_T("%s"),
            				MessageBox(str2,"Message");
            				return TRUE;
            			}
            		}
            		else
            		{
            			str3.Format(\_T("Unable to create the SQL Server object.\\n"));
            	
            		}
            	}
            	catch(\_com\_error pCE)
            	{
            		str2.Format(\_T("\\n%s Error: %ld\\r\\n%s\\r\\n%s\\r\\n"),
            			(TCHAR\*)pCE.Source(),
            			pCE.Error(),
            			(TCHAR\*)pCE.Description(),
            			(TCHAR\*)pCE.ErrorMessage());
            	}
            
            
            }
            else
            {
            	str2.Format(\_T("Call to CoInitialize failed.\\n"));
            }
            

            Use database command code is here

            QueryResultsPtr Qry;
            _SQLServer2Ptr spSQLServer;
            CString udata="use 'databasename'";
            //(databasename is like master ,use create database)
            Qry=spSQLServer->ExecuteWithResults((_bstr_t)udata,(LONG)udata.GetLength());

            Select command is running fine like this

            CString sel="select * from 'Database name'.dbo.'Table Name'"
            Qry=spSQLServer->ExecuteWithResults((_bstr_t)sel,(LONG)sel.GetLength());

            Can any one help me why

            USE 'Database name'

            not working. Plz help me

            P Offline
            P Offline
            PCuong1983
            wrote on last edited by
            #8

            uhm, I think: the USE keyword (in t-sql) follow by YourDBName (YourDBName without quote) like this USE YourBDName or USE [YourBDName]

            M 1 Reply Last reply
            0
            • M MsmVc

              thanks ,i use code which is given by you.But i got error

              Microsoft SQL-DMO (ODBC SQLState: 42000) Error: -2147221402 [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'databasename'. Invalid STDGMEDIUM structure

              C Offline
              C Offline
              Code o mat
              wrote on last edited by
              #9

              How about CString udata="use databasename"; ? Btw do you know that -according to msdn- Microsoft recommends not using sql-dmo in newer products because it will be removed by them?

              > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <

              M 1 Reply Last reply
              0
              • C Code o mat

                How about CString udata="use databasename"; ? Btw do you know that -according to msdn- Microsoft recommends not using sql-dmo in newer products because it will be removed by them?

                > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <

                M Offline
                M Offline
                MsmVc
                wrote on last edited by
                #10

                thanks for information. So what i use?Plz help me

                C 1 Reply Last reply
                0
                • P PCuong1983

                  uhm, I think: the USE keyword (in t-sql) follow by YourDBName (YourDBName without quote) like this USE YourBDName or USE [YourBDName]

                  M Offline
                  M Offline
                  MsmVc
                  wrote on last edited by
                  #11

                  Thank But i test both case there is no effect in out put.Still same problem here.

                  P 1 Reply Last reply
                  0
                  • M MsmVc

                    thanks for information. So what i use?Plz help me

                    C Offline
                    C Offline
                    Code o mat
                    wrote on last edited by
                    #12

                    This[^] is where i found that you should avoid using it, just to show you i didn't make that up. Otherwise, i don't know what else there is, i guess you should ask Microsoft (look around MSDN), or you could try using Oracle Database 10g client[^], i think it is an ODBC "interface" of somesort...

                    > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <

                    1 Reply Last reply
                    0
                    • M MsmVc

                      Thank But i test both case there is no effect in out put.Still same problem here.

                      P Offline
                      P Offline
                      PCuong1983
                      wrote on last edited by
                      #13

                      Did you put USE YourDBName query and select query in same connection session ? WHEN and WHERE did you use SELECT DB_NAME() AS DataBaseName ?

                      M 1 Reply Last reply
                      0
                      • P PCuong1983

                        Did you put USE YourDBName query and select query in same connection session ? WHEN and WHERE did you use SELECT DB_NAME() AS DataBaseName ?

                        M Offline
                        M Offline
                        MsmVc
                        wrote on last edited by
                        #14

                        See as in first post first i make connection then i use

                        CString tr="USE tes";
                        //(tes is a database)
                        Qry1=spSQLServer->ExecuteWithResults((_bstr_t)tr);

                        this code. After that i use

                        SELECT DB_NAME() AS DataBaseName

                        If i am wrong then pls help me

                        P 1 Reply Last reply
                        0
                        • M MsmVc

                          See as in first post first i make connection then i use

                          CString tr="USE tes";
                          //(tes is a database)
                          Qry1=spSQLServer->ExecuteWithResults((_bstr_t)tr);

                          this code. After that i use

                          SELECT DB_NAME() AS DataBaseName

                          If i am wrong then pls help me

                          P Offline
                          P Offline
                          PCuong1983
                          wrote on last edited by
                          #15

                          :( sorry This link: http://msdn.microsoft.com/en-us/library/ms131540.aspx[^] may help you.

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups