SoftTree Technologies SoftTree Technologies
Technical Support Forums
RegisterSearchFAQMemberlistUsergroupsLog in
SQL Assisntant Auto Complete and MS SQL Server

 
Reply to topic    SoftTree Technologies Forum Index » SQL Assistant View previous topic
View next topic
SQL Assisntant Auto Complete and MS SQL Server
Author Message
denis2710



Joined: 12 Apr 2013
Posts: 6
Country: Russian Federation

Post SQL Assisntant Auto Complete and MS SQL Server Reply with quote
Hello.
I have SQL Assistant 6.3.171 and MS SQL Server 2008R2.
I set "With schema name" for "Always Fully Qualify Object Names" option.
For auto complete SQL Assistant always use schema name which set as default schema for current user.(even db object doesn't exist in default user schema)
Why SQL Assistant doesn't get schema name of current db object?
How can I change it?
Fri Apr 12, 2013 2:29 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7852

Post Reply with quote
I assume you are using SQL Assistant with SQL Server Management Studio 2008 (SSMS here and later)

Let's check that you have changed "qualify" settings in the correct place.
1. In SSMS, right-click in the editor and choose SQL Assistant -> Options menu
2. Click "DB Options" tab, then select "SQL Server" assistance type on the left (this is the second item)
3. On the right, expand the "Auto Complete" group of options
4. Set "Always Fully Qualify Object Names" option as required and then click Ok.

Try entering some query and check if that works.

Assuming it does work, restart SSMS, repeat steps 1 to 3. Verify the value for the option is still the same. If not exist SSMS, and start it in Run As Administrator mode. Repeat steps 1 to 4 again.
Fri Apr 12, 2013 7:57 am View user's profile Send private message
denis2710



Joined: 12 Apr 2013
Posts: 6
Country: Russian Federation

Post Reply with quote
Hello.
This is my settings

For example:
I have user test.

This is my test database

I type "select * from" and call SQL Assistance context list

Why Sql Assistance doesn't show all table from all schemes?
After that I select ErrorLog table and press enter and I get

Table test.errorlog doen't exists in test db.
How can I change it?
Mon Apr 15, 2013 6:16 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7852

Post Reply with quote
Content of SQL Assistant popups and dialogs is filled from DB Queries which you can see on DB Options tab. What these queries return depends on your connection context. Basically, if you connect as user test, you will see only the things that the database server makes visible to user test. Additionally. If the user doesn't have permissions to query all system catalog tables and use schema_name() function name, then by default SQL Assistant will user's user's name as schema name instead of nulls.

you can easily test the above. Connect to your server as user test.
Copy "Context (MSSQL)" query text to SSMS and execute it. check the results and see if they are correct. If not, fix user permissions.
Next, do the same for "Schemas (MSSQL)" query, replacing in the query text $DB_NAME$ with AdventureWorks
Lastly, try the same for "Objects (MSSQL) + Typed Synonyms" replaceing $DB_NAME, and also replacing :SCHEMA_ID with the number returned from the "Schemas (MSSQL)" query.

The results should match content of SQL Assistant's popups and behavior.
Mon Apr 15, 2013 9:09 am View user's profile Send private message
denis2710



Joined: 12 Apr 2013
Posts: 6
Country: Russian Federation

Post Reply with quote
As You can see(screenshot 2 from my previous post ) user test is db_owner and he has all permission for all objects in all schemes in this database.
As I see in SQL Profiler, when I call context menu with objects list, SQL Assistant execute once “Context” query(return default user scheme - in this case test).After that Assistant execute “Objects” query twice for dbo and test schemes. Why SQL Assistant did execute only for 2 schemes? “Schemas ” query retunes all schemes in database.
I don’t understand why SQL Assistant does use default users schema for auto complete, why he doesn’t get scheme of selected object?
Tue Apr 16, 2013 3:14 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7852

Post Reply with quote
Please execute the queries I asked to execute in the previous post. they will provide answers to your questions and help us with troubleshooting the issue.
Tue Apr 16, 2013 8:41 am View user's profile Send private message
denis2710



Joined: 12 Apr 2013
Posts: 6
Country: Russian Federation

Post Reply with quote
Hello.
This is "Context" with result
Code:
if @@version like 'Microsoft SQL Server 2005%'
or @@version like 'Microsoft SQL Server 2008%'
or @@version like '%SQL Server 2012%'
or @@version like '%Denali%'
   EXEC ('select
    SERVERPROPERTY(''ServerName''),
    SYSTEM_USER,
    DB_NAME(),
    ISNULL(SCHEMA_NAME(), ''dbo'')')
else
   EXEC ('select
    SERVERPROPERTY(''ServerName''),
    SYSTEM_USER,
    DB_NAME(),
    ISNULL(USER_NAME(), ''dbo'')')

****\SQL2008R2   test   AdventureWorks   test


This is "Schemas" query with result
Code:

if @@version like 'Microsoft SQL Server 2005%'
   or @@version like 'Microsoft SQL Server 2008%'
   or @@version like '%SQL Server 2012%'
   or @@version like '%Denali%'
    select name collate Latin1_General_CI_AS
          ,'SC'
          ,schema_id
    from   AdventureWorks.sys.schemas
    where  schema_id  <16384> 0 then 'SR'
            else        'SC'
       end
      ,cast ( uid as int )
from   AdventureWorks.dbo.sysusers
where  issqluser = 1
       or  isntname = 1
       or  issqlrole = 1
       or  isapprole = 1
   
   union all
select name collate Latin1_General_CI_AS
      ,'SL'
      ,0
from   master.dbo.syslogins




    schema_id
    -------------------------------------------------------------------------------------------------------------------------------- ---- -----------
    dbo SC 1
    guest SC 2
    INFORMATION_SCHEMA SC 3
    sys SC 4
    HumanResources SC 5
    Person SC 6
    Production SC 7
    Purchasing SC 8
    Sales SC 9
    test SC 10
    public SR 0
    db_owner SR 16384
    db_accessadmin SR 16385
    db_securityadmin SR 16386
    db_ddladmin SR 16387
    db_backupoperator SR 16389
    db_datareader SR 16390
    db_datawriter SR 16391
    db_denydatareader SR 16392
    db_denydatawriter SR 16393
    sa SL 1
    public SR 2
    sysadmin SR 3
    securityadmin SR 4
    serveradmin SR 5
    setupadmin SR 6
    processadmin SR 7
    diskadmin SR 8
    dbcreator SR 9
    bulkadmin SR 10
    test SL 270

This is "Object" query with result for several schemas

Code:

declare @SCHEMA_ID int ;

set @SCHEMA_ID = schema_id ( 'dbo' );

if @@version like 'Microsoft SQL Server 2005%'
   or @@version like 'Microsoft SQL Server 2008%'
   or @@version like '%SQL Server 2012%'
   or @@version like '%Denali%'
    select name
          ,type
          ,object_id
          ,create_date
          ,modify_date
    from   AdventureWorks.sys.all_objects
    where  type in ('U'
                   ,'S'
                   ,'V'
                   ,'P'
                   ,'X'
                   ,'RF'
                   ,'FN'
                   ,'TF'
                   ,'IF'
                   ,'SN'
                   ,'PC'
                   ,'FT'
                   ,'FS'
                   ,'TR')
           and (
                   schema_id = @SCHEMA_ID
                   or (
                          1 = @SCHEMA_ID
                          and user_name() = 'dbo'
                          and schema_id = 4
                          and name in ('sysobjects'
                                      ,'sysindexes'
                                      ,'syscolumns'
                                      ,'systypes'
                                      ,'syscomments'
                                      ,'sysfiles1'
                                      ,'syspermissions'
                                      ,'sysusers'
                                      ,'sysproperties'
                                      ,'sysdepends'
                                      ,'sysreferences'
                                      ,'sysfulltextcatalogs'
                                      ,'sysindexkeys'
                                      ,'sysforeignkeys'
                                      ,'sysmembers'
                                      ,'sysprotects'
                                      ,'sysfulltextnotify'
                                      ,'sysfiles'
                                      ,'sysfilegroups')
                      )
               )
           and not ( name = 'dtproperties' )
           and not ( name like 'dt%' and type = 'P' )
else
    select name
          ,xtype
          ,id
          ,crdate
          ,crdate
    from   AdventureWorks.dbo.sysobjects
    where  xtype in ( 'U' ,'S' ,'V' ,'P' ,'X' ,'RF' ,'FN' ,'TF' ,'IF' ,'TR' )
           and uid = @SCHEMA_ID
           and not ( name = 'dtproperties' )
           and not ( name like 'dt%' and xtype = 'P' )
     
/*
 *
 */     
     
set @SCHEMA_ID = schema_id ( 'test' );


if @@version like 'Microsoft SQL Server 2005%'
   or @@version like 'Microsoft SQL Server 2008%'
   or @@version like '%SQL Server 2012%'
   or @@version like '%Denali%'
    select name
          ,type
          ,object_id
          ,create_date
          ,modify_date
    from   AdventureWorks.sys.all_objects
    where  type in ('U'
                   ,'S'
                   ,'V'
                   ,'P'
                   ,'X'
                   ,'RF'
                   ,'FN'
                   ,'TF'
                   ,'IF'
                   ,'SN'
                   ,'PC'
                   ,'FT'
                   ,'FS'
                   ,'TR')
           and (
                   schema_id = @SCHEMA_ID
                   or (
                          1 = @SCHEMA_ID
                          and user_name() = 'dbo'
                          and schema_id = 4
                          and name in ('sysobjects'
                                      ,'sysindexes'
                                      ,'syscolumns'
                                      ,'systypes'
                                      ,'syscomments'
                                      ,'sysfiles1'
                                      ,'syspermissions'
                                      ,'sysusers'
                                      ,'sysproperties'
                                      ,'sysdepends'
                                      ,'sysreferences'
                                      ,'sysfulltextcatalogs'
                                      ,'sysindexkeys'
                                      ,'sysforeignkeys'
                                      ,'sysmembers'
                                      ,'sysprotects'
                                      ,'sysfulltextnotify'
                                      ,'sysfiles'
                                      ,'sysfilegroups')
                      )
               )
           and not ( name = 'dtproperties' )
           and not ( name like 'dt%' and type = 'P' )
else
    select name
          ,xtype
          ,id
          ,crdate
          ,crdate
    from   AdventureWorks.dbo.sysobjects
    where  xtype in ( 'U' ,'S' ,'V' ,'P' ,'X' ,'RF' ,'FN' ,'TF' ,'IF' ,'TR' )
           and uid = @SCHEMA_ID
           and not ( name = 'dtproperties' )
           and not ( name like 'dt%' and xtype = 'P' )
     
     /*
 *
 */     
     
set @SCHEMA_ID = schema_id ( 'Production' );


if @@version like 'Microsoft SQL Server 2005%'
   or @@version like 'Microsoft SQL Server 2008%'
   or @@version like '%SQL Server 2012%'
   or @@version like '%Denali%'
    select name
          ,type
          ,object_id
          ,create_date
          ,modify_date
    from   AdventureWorks.sys.all_objects
    where  type in ('U'
                   ,'S'
                   ,'V'
                   ,'P'
                   ,'X'
                   ,'RF'
                   ,'FN'
                   ,'TF'
                   ,'IF'
                   ,'SN'
                   ,'PC'
                   ,'FT'
                   ,'FS'
                   ,'TR')
           and (
                   schema_id = @SCHEMA_ID
                   or (
                          1 = @SCHEMA_ID
                          and user_name() = 'dbo'
                          and schema_id = 4
                          and name in ('sysobjects'
                                      ,'sysindexes'
                                      ,'syscolumns'
                                      ,'systypes'
                                      ,'syscomments'
                                      ,'sysfiles1'
                                      ,'syspermissions'
                                      ,'sysusers'
                                      ,'sysproperties'
                                      ,'sysdepends'
                                      ,'sysreferences'
                                      ,'sysfulltextcatalogs'
                                      ,'sysindexkeys'
                                      ,'sysforeignkeys'
                                      ,'sysmembers'
                                      ,'sysprotects'
                                      ,'sysfulltextnotify'
                                      ,'sysfiles'
                                      ,'sysfilegroups')
                      )
               )
           and not ( name = 'dtproperties' )
           and not ( name like 'dt%' and type = 'P' )
else
    select name
          ,xtype
          ,id
          ,crdate
          ,crdate
    from   AdventureWorks.dbo.sysobjects
    where  xtype in ( 'U' ,'S' ,'V' ,'P' ,'X' ,'RF' ,'FN' ,'TF' ,'IF' ,'TR' )
           and uid = @SCHEMA_ID
           and not ( name = 'dtproperties' )
           and not ( name like 'dt%' and xtype = 'P' )
           
/*and so on*/           




    name type object_id create_date modify_date
    -------------------------------------------------------------------------------------------------------------------------------- ---- ----------- ----------------------- -----------------------
    uspPrintError P 37575172 2012-02-13 16:11:35.147 2012-02-13 16:11:35.147
    uspLogError P 53575229 2012-02-13 16:11:35.150 2012-02-13 16:11:35.150
    ufnLeadingZeros FN 69575286 2012-02-13 16:11:35.160 2012-02-13 16:11:35.160
    AWBuildVersion U 181575685 2012-02-13 16:11:35.337 2012-02-13 16:11:46.590
    ufnGetAccountingStartDate FN 1595152728 2012-02-13 16:12:00.920 2012-02-13 16:12:00.920
    ufnGetAccountingEndDate FN 1611152785 2012-02-13 16:12:00.943 2012-02-13 16:12:00.943
    ufnGetContactInformation TF 1627152842 2012-02-13 16:12:00.950 2012-02-13 16:12:00.950
    ufnGetProductDealerPrice FN 1691153070 2012-02-13 16:12:00.963 2012-02-13 16:12:00.963
    ufnGetProductListPrice FN 1707153127 2012-02-13 16:12:00.977 2012-02-13 16:12:00.977
    ufnGetProductStandardCost FN 1723153184 2012-02-13 16:12:00.990 2012-02-13 16:12:00.990
    ufnGetStock FN 1739153241 2012-02-13 16:12:01.000 2012-02-13 16:12:01.000
    ufnGetDocumentStatusText FN 1755153298 2012-02-13 16:12:01.013 2012-02-13 16:12:01.013
    ufnGetPurchaseOrderStatusText FN 1771153355 2012-02-13 16:12:01.027 2012-02-13 16:12:01.027
    ufnGetSalesOrderStatusText FN 1787153412 2012-02-13 16:12:01.037 2012-02-13 16:12:01.037
    uspGetBillOfMaterials P 1803153469 2012-02-13 16:12:01.050 2012-02-13 16:12:01.050
    uspGetEmployeeManagers P 1819153526 2012-02-13 16:12:01.063 2012-02-13 16:12:01.063
    uspGetManagerEmployees P 1835153583 2012-02-13 16:12:01.077 2012-02-13 16:12:01.077
    uspGetWhereUsedProductID P 1851153640 2012-02-13 16:12:01.103 2012-02-13 16:12:01.103
    DatabaseLog U 2105058535 2012-02-13 16:11:35.123 2012-02-13 16:11:46.930
    ErrorLog U 2137058649 2012-02-13 16:11:35.130 2012-02-13 16:11:35.147

    (20 row(s) affected)

    name type object_id create_date modify_date
    -------------------------------------------------------------------------------------------------------------------------------- ---- ----------- ----------------------- -----------------------
    UserTestTable U 1915153868 2013-04-16 09:51:43.543 2013-04-16 09:52:27.400

    (1 row(s) affected)

    name type object_id create_date modify_date
    -------------------------------------------------------------------------------------------------------------------------------- ---- ----------- ----------------------- -----------------------
    ProductPhoto U 18099105 2012-02-13 16:11:35.457 2012-02-13 16:11:59.290
    ProductProductPhoto U 50099219 2012-02-13 16:11:35.467 2012-02-13 16:11:59.290
    ProductReview U 98099390 2012-02-13 16:11:35.473 2012-02-13 16:11:59.317
    TransactionHistory U 110623437 2012-02-13 16:11:35.563 2012-02-13 16:12:00.397
    ProductSubcategory U 162099618 2012-02-13 16:11:35.477 2012-02-13 16:11:59.320
    TransactionHistoryArchive U 190623722 2012-02-13 16:11:35.567 2012-02-13 16:11:52.320
    BillOfMaterials U 213575799 2012-02-13 16:11:35.340 2012-02-13 16:11:58.873
    UnitMeasure U 270624007 2012-02-13 16:11:35.570 2012-02-13 16:11:59.323
    WorkOrder U 446624634 2012-02-13 16:11:35.580 2012-02-13 16:12:00.663
    WorkOrderRouting U 526624919 2012-02-13 16:11:35.583 2012-02-13 16:12:00.447
    Culture U 597577167 2012-02-13 16:11:35.353 2012-02-13 16:11:59.280
    Document U 837578022 2012-02-13 16:11:35.387 2012-02-13 16:11:59.230
    Illustration U 1269579561 2012-02-13 16:11:35.403 2012-02-13 16:11:59.250
    iWorkOrder TR 1291151645 2012-02-13 16:12:00.660 2012-02-13 16:12:00.660
    uWorkOrder TR 1307151702 2012-02-13 16:12:00.663 2012-02-13 16:12:00.663
    Location U 1365579903 2012-02-13 16:11:35.407 2012-02-13 16:12:00.447
    Product U 1461580245 2012-02-13 16:11:35.410 2012-02-13 16:12:00.787
    vProductAndDescription V 1467152272 2012-02-13 16:12:00.750 2012-02-13 16:12:00.787
    vProductModelCatalogDescription V 1483152329 2012-02-13 16:12:00.807 2012-02-13 16:12:00.807
    vProductModelInstructions V 1499152386 2012-02-13 16:12:00.817 2012-02-13 16:12:00.817
    ScrapReason U 1650104919 2012-02-13 16:11:35.530 2012-02-13 16:12:00.427
    ProductCategory U 1701581100 2012-02-13 16:11:35.417 2012-02-13 16:11:59.320
    ProductCostHistory U 1749581271 2012-02-13 16:11:35.417 2012-02-13 16:11:59.213
    ProductDescription U 1813581499 2012-02-13 16:11:35.420 2012-02-13 16:12:00.787
    ProductDocument U 1861581670 2012-02-13 16:11:35.427 2012-02-13 16:11:59.230
    ProductInventory U 1893581784 2012-02-13 16:11:35.437 2012-02-13 16:11:59.237
    ProductListPriceHistory U 1989582126 2012-02-13 16:11:35.437 2012-02-13 16:11:59.247
    ProductModel U 2053582354 2012-02-13 16:11:35.440 2012-02-13 16:12:00.787
    ProductModelIllustration U 2101582525 2012-02-13 16:11:35.443 2012-02-13 16:11:59.250
    ProductModelProductDescriptionCulture U 2133582639 2012-02-13 16:11:35.453 2012-02-13 16:12:00.787

    (30 row(s) affected)



Wed Apr 17, 2013 4:41 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7852

Post Reply with quote
The "Context" query returns
-----------------------------------
current user = test
current user's schema = test
------------------------------------
this seems to be correct



The "Schemas" query also returns "test" schema, which is good too.


The "Objects" query for the test schema returns just one table UserTestTable, which seems to be correct too. And it correctly returns ErrorLog table for the "dbo" schema.

So all queries seem to return the expected results. However, they don't match the content of the popup on your screenshot. In the popup list for objects, only objects in the users's current schema appear in the list at the top and without schema name. Objects in other schemas appear folded in the schema level (see the attached screenshot).

In the current execution context from SQL Assistant's point of view, your current schema is dbo, not test as returned by the Context query and expected by SQL Assistant. and that's why when you select ErrorLog it is inserted as test.ErrorLog, not as dbo.ErrorLog.


Please check your SSMS settings or queries you are executing. somehow your current schema changes to dbo behind the scenes and SQL Assistant is not aware of that change. If thinks you are still in the test schema.

I also noticed that you are using old catalog queries from version 6.2 or older. I strongly recommend that you reload your SQL Assistant settings using Import/Export in the Options dialog and then picking the default settings.



Wed Apr 17, 2013 8:29 am View user's profile Send private message
denis2710



Joined: 12 Apr 2013
Posts: 6
Country: Russian Federation

Post Reply with quote
My SQL Assistant version is 6.3.171.I haven’t changed anything in db scripts.
I reloaded my settings using Import/Export to default.Unfortunately, I still get this problem. As I wrote SQL Assistant get object from default user schema(test) and dbo, and think these objects from test schema.


Thu Apr 18, 2013 3:40 am View user's profile Send private message
denis2710



Joined: 12 Apr 2013
Posts: 6
Country: Russian Federation

Post Reply with quote
How I can see there is no solution for my problem...
Mon May 27, 2013 8:02 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7852

Post Reply with quote
I suggest to test the same type of login with a different editor. For example, with Notepad, enabling Notepad as a target in SQL Assistant settings. This is to exclude SQL Server Management Studio as a factor and ensure it is not the target environment that is interfering somehow. Also, with Notepad, you can try a different connection type, for example ODBC, instead of ADO. This way all other external factors can be excluded 1 by 1 until we figure out what's causing the issue.
Mon May 27, 2013 8:54 am View user's profile Send private message
Display posts from previous:    
Reply to topic    SoftTree Technologies Forum Index » SQL Assistant All times are GMT - 4 Hours
Page 1 of 1

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


 

 

Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Flowers Online.