Quantcast
Channel: SQL Server Database Engine Forum
Viewing all 15872 articles
Browse latest View live

Polybase : External Data Source Issue with Mongodb

$
0
0

Hi All,

I have been trying to access mongodb(version 4.0) collection from SQL Server using polybase feature.  Mongodb is up and running with remote access from SQL Server. I am following the instruction as as described in the link Configure PolyBase to access external data in MongoDB

I am receiving error on creating External Data Source , polybase logs have not recorded any issue with the connection to mongodb. The Polybase services are up and running without any issue (This instance is  standalone and not connected to AD). 

Any one faced similar issues , please help and advice

CREATE EXTERNAL DATA SOURCE eds_mongodb
WITH (

LOCATION = 'mongodb://10.0.2.15:27017',
-- PUSHDOWN = ON | OFF,
 CREDENTIAL = Mongo_Polybase_credentials
);

CREATE EXTERNAL TABLE mongo_dfgd(
_idnvarchar(2000),
namevarchar(200),
address  varchar(300),
street varchar(200)
)
WITH (
LOCATION='mongosg.test1',
DATA_SOURCE= eds_mongodb
);

Error on executing Create external table command

Msg 105082, Level 16, State 1, Line 36
105082;Generic ODBC error: [Microsoft][MongoDBODBC] (110) Error from MongoDB Client: No suitable servers found (`serverSelectionTryOnce` set): [socket timeout calling ismaster on '10.0.2.15:27017'] (Error Code: 13053) Additional error <2>: ErrorMsg: [Microsoft][MongoDBODBC] (110) Error from MongoDB Client: No suitable servers found (`serverSelectionTryOnce` set): [socket timeout calling ismaster on '10.0.2.15:27017'] (Error Code: 13053), SqlState: HY000, NativeError: 110 .

Regards

Sufian



SQL Agent Job Audit

$
0
0

Dear All,

I would like to find out when and who executed, stopped a particular SQL Agent job. I have looked into the following: Job history, sql error logs, event logs etc. nut unfortunately I'm unable to find the information as the job is owned by a service account. Would it be possible to find such information please? Thank you in advance! 

Triggers not appearing in SSMS, not under tables, not in sys.triggers, not in sys.objects, nowhere!

$
0
0
I tried to add a trigger the other day. IT said that the query was successful, but when I tried to test it, the application froze. It stopped freezing when I closed SSMS. I then tried to look for the trigger; It did not show up, nor did any other triggers. I know that there is at least one more trigger in the system, and I can't find that one either. Is there a way to get SQL Server to rebuild the triggers?

Cant bulk import data

$
0
0

Hi when i make my tabels and try to bulk import only Production.[Order Details] and if i'm not mistaking Production.Products can bulk import but customers and orders i get error on. It looks lite my foreignkeys is locking me or something,  i get som error like Msg 4864, Level 16, State 1, Line 2
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 2, column 1 (CustomerID).
Can somebody help me.


CREATE TABLE Sales.Customers
(
    CustomerID int NOT NULL PRIMARY KEY,
    CompanyName nvarchar(60) NOT NULL,
    ContactName nvarchar(30),
    ContactTitle nvarchar(30),
    Adress nvarchar(60),
    City nvarchar(15),
    Region nvarchar(15),
    PostalCode nvarchar(10),
    Country nvarchar(15),
    Phone nvarchar(24)
)
GO

CREATE TABLE Production.Orders
(
    OrderID int IDENTITY NOT NULL PRIMARY KEY,
    CustomerID int NOT NULL FOREIGN KEY REFERENCES Sales.Customers(CustomerID),
    OrderDate datetime,
    RequiredDate datetime,
    ShippedDate datetime
)
GO

CREATE TABLE Production.Products
(
    ProductID int NOT NULL PRIMARY KEY,
    ProductName nvarchar(40) NOT NULL,
    QuantityPerUnit nvarchar(20),
    UnitPrice decimal(8,2)
)
GO

CREATE TABLE Production.[Order Details]
(
    OrderID int NOT NULL FOREIGN KEY REFERENCES Production.Orders(orderID),
    ProductID int NOT NULL FOREIGN KEY REFERENCES Production.Products(ProductID),
    UnitPrice decimal(8,2) NOT NULL,
    Quantity int NOT NULL
    PRIMARY KEY (OrderID, ProductID)
)
GO

USE Northwind
BULK INSERT Sales.Customers
FROM 'E:\Customers.txt'
WITH (FIELDTERMINATOR = ';', ROWTERMINATOR = '\n', FIRSTROW = 2, CODEPAGE = '1252');

etc....


CAST decimal as varbinary

$
0
0

Run the foll. code snippet -

createtable #t1(
c1decimal(9, 1)
)
insert#t1
values(99999999.9)

selectc1, CAST(c1 AS varbinary(60)), DATALENGTH(c1)
from#t1

As per SQL Server Books online, col. C1 should have a size of 5 bytes. That is what DATALENGTH also reports.

However, CASTing the col. as varbinary (to check internal representation of a decimal datatype col.) returns 8 bytes of data.

That's a bit perplexing since, the actual data is 5 bytes, however, CAST is reporting extra info..

Is this some undocumented behaviour of CAST of decimal to varbinary or is there some more understanding required with regards to decimal data type's internal storage - Any thoughts?

Thanks.

SQL Server 2016 data conversion

$
0
0

there is a KB https://support.microsoft.com/en-us/help/4010261/sql-server-and-azure-sql-database-improvements-in-handling-some-data-t

talking about data conversion precision improvement. in the page it mention the following

Starting with SQL Server 2016, both SQL Server and Azure SQL Database include improvements to the precision of the following operations:


  • Uncommon data type conversions. These include the following:

    • float/integer to/from datetime/smalldatetime
    • real/float to/from numeric/money/smallmoney
    • float to real
  • Some cases of DATEPART/DATEDIFF andDEGREES
  • CONVERT with aNULL style

But so far I can just see datetime2 has the improvement(enhancement ) in Compatible level 130 .

In CL 130 : datetime2 will show 2019-01-09 14:15:29.6833333

In CL < 130 : datetime2 will show 2019-01-09 14:15:29.6833000

But for other datatype conversion mentioned : float/real/money..... are there any example ?

1. And another problem is that the article mention recommend to validate after upgrade to SQL 2016 and before change to CL 130. The validation time maybe long(hard to estimate) as there are DBCC checktable. Is it possible to do before upgrade ?

2. It mention "Rebuild any structures that you identified in step 1" actually how to do it ? i.e. drop the computed column and add again ????? rebuild the view ??

 

SQL Server Alert System: 'Severity 019'

$
0
0

while run below query

query: ( record count 56250028)

insert into ledger.dbo.ledger_transactions_details(amount,account,description,transaction_id,account_details)  
select  amount,account,description,id,account_details  from ledger_transactions_detailstemp1

Error:

DESCRIPTION:    The instance of the SQL Server Database Engine cannot obtain a LOCK resource at this time. Rerun your statement when there are fewer active users. Ask the database administrator to check the lock and memory configuration for this instance, or to check for long-running transactions.

Different behavior when running a statement from SSMS and from SSIS

$
0
0

I'm using SQL 2012

I'm running the following statement. When running it from SSMS - it deletes a few rows, as there are a few rows in the table that meet the criteria. BUT, when I run it from SSIS (or BIDS) it doesn't delete any row, as no row meets the criteria.

What could cause the change?

I checked and all setting of Ansi_nulls etc. are identical (@@options is the same when running from within SSMS or SSIS).


 delete TBL
where isnull(Col1,'')+isnull(Col2,'')+isnull(col3,'')+isnull(col4,'')+isnull(col5,'')
 +isnull(col6,'')+isnull(col7,'')+isnull(col8,'') = '';

Thanks


Who will be announced as the next SQL Server Database Engine Guru? Read more about January 2019 competition!!

$
0
0


What is TechNet Guru Competition?

Each month the TechNet Wiki council organizes a contest of the best articles posted that month. This is your chance to be announced as MICROSOFT TECHNOLOGY GURU OF THE MONTH!

One winner in each category will be selected each month for glory and adoration by the MSDN/TechNet Ninjas and community as a whole. Winners will be announced in dedicated blog post that will be published in Microsoft Wiki Ninjas blog, a tweet from the Wiki Ninjas Twitter account, links will be published at Microsoft TNWiki group on Facebook, and other acknowledgement from the community will follow.

Some of our biggest community voices and many MVPs have passed through these halls on their way to fame and fortune.

If you have already made a contribution in the forums or gallery or you published a nice blog, then you can simply convert it into a shared wiki article, reference the original post, and register the article for the TechNet Guru Competition. The articles must be written in January 2019 and must be in English. However, the original blog or forum content can be from beforeJanuary 2019.

Come and see who is making waves in all your favorite technologies. Maybe it will be you!


Who can join the Competition?

Anyone who has basic knowledge and the desire to share the knowledge is welcome. Articles can appeal to beginners or discusse advanced topics. All you have to do is to add your article to TechNet Wiki from your own specialty category.


How can you win?

  1. Please copy/Write over your Microsoft technical solutions and revelations to TechNetWiki.
  2. Add a link to your new article on THIS WIKI COMPETITION PAGE (so we know you've contributed)
  3. (Optional but recommended) Add a link to your article at the TechNetWiki group on Facebook. The group is very active and people love to help, you can get feedback and even direct improvements in the article before the contest starts.

Do you have any question or want more information?

Feel free to ask any questions below, or Join us at the official MicrosoftTechNet Wiki groups on facebook. Read More about TechNet Guru Awards.

If you win, people will sing your praises online and your name will be raised as Guru of the Month.


PS: Above top banner came from Vimal Kalathil.


User statement blocked by a SCH-M lock on a table invisible to him

$
0
0

When querying the list of the tables, a user may be blocked by another process because of an object even if he doesn't have any permission on this object.

Repro steps (on Azure SQL) :

1- Create a database (Basic is enough)

2 - Create the users and structures (with an admin account)

CREATE SCHEMA Schema1;
GO
CREATE SCHEMA Schema2;
GO
CREATE TABLE Schema1.TableSchema1 (Id int IDENTITY PRIMARY KEY, Data nvarchar(max));
GO
CREATE TABLE Schema2.TableSchema2 (Id int IDENTITY PRIMARY KEY, Data nvarchar(max));
GO
CREATE ROLE Role1;
GO
GRANT SELECT ON Schema::Schema1 to Role1;
GO
CREATE ROLE Role2;
GO
GRANT ALTER ON Schema::Schema2 to Role2;
GO
CREATE USER User1 WITH PASSWORD='ComplexPassword123'
GO
exec sp_addrolemember 'Role1','User1'
GO
CREATE USER User2 WITH PASSWORD='ComplexPassword123'
GO
exec sp_addrolemember 'Role2','User2'
GO

3 - Connect as User1 on this database (with the password ComplexPassword123) and run the following statement (and keep the conection opened)

select * from INFORMATION_SCHEMA.TABLES

Whe can see 2 tables, sys.database_firewall_rules and Schema1.TableSchema1

4 - Connect as User2 (same database, same password), run the following statement (and keep the connection opened)

begin transaction
truncate table Schema2.TableSchema2

5 - Go back to the session of User1, and re-run the statement

select * from INFORMATION_SCHEMA.TABLES

It is blocked (running...)

6 - Open a session with an admin account an run :

select distinct t.name as [Table],locks.request_mode as [Mode],request_status as [Status],p.name as Connected
from (select resource_associated_entity_id from sys.dm_tran_locks where request_status='WAIT') locked
 join sys.tables t on t.object_id=locked.resource_associated_entity_id
 join sys.dm_tran_locks locks on locks.resource_associated_entity_id=locked.resource_associated_entity_id
 join sys.dm_exec_sessions s on s.session_id=locks.request_session_id
 join sys.database_principals p on p.sid=s.security_id

We can see the User1 is waiting for a Sch-S lock on the table TableSchema2, while he doesn't have any permission (SELECT, ...) on this table.

The filter on the list of the tables is applied after the creation of a first and complete list of all the tables, so this complete listing is blocked by the other process, while it shoudn't.


Jean-Nicolas BERGER
http://blog.sqlserver.fr

HA nodes

$
0
0

What's the limitation on failover cluster number of nodes for SQL 2016 Standard and enterprise edition ?

SQL error 5171

$
0
0
I'm getting an error while operating the SQL server. It displays as SQL server error 5171. I'm not able to resolve this error. Please, somebody, help me get out of this.

.Net framework / Ado.net compatibility

$
0
0

Where can I find the ado.net compatibility matix with SQL server ?

How do I see the full SQLl/Query text of a spid?

$
0
0

How do I see the full SQLl/Query text of a spid?

I use different ways to get the query, the problem is it truncates the end, so I cannot see the entire query/sql text. Is there another way to a query/sql text that is being run?


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

Encountered fatal system assertion check involving CLR UDF, calculated column, and columnstore index.

$
0
0

We encountered a situation where a table has a calculated column that uses a scalar user-defined function (UDF) defined AS an EXTERNAL NAME (is contained in a custom assembly) that returns an NVARCHAR(MAX) and the table has a nonclustered columnstore index that includes the column that is passed into the function of the calculated column, a fatal system assertion check occurs (Msg 596, Level 21, State 1).

We encountered this behavior in versions 14.0.3045.24, 14.0.3048.4, and 14.14.0.3049.1.  We have not checked other versions.

Altering the return of the UDF function from NVARCHAR(MAX) to NVARCHAR(64) results in the successful execution of queries that use the calculated column and the fatal system assertion check no longer occurs.

Perhaps something can be done to warn of or prevent the combination of columnstore indexes including columns that participate in UDF calculations that return NVARCHAR(MAX) at the time the index or the calculated column is created.

The following TSQL describes the scenario:

/*** In our implementation this CLR UDF removes all non-alphanumeric characters,
 though we found that the logic here doesn't affect the issue. It can return the
 string without modification and the issue still occurs. ***/
CREATE FUNCTION [per].[SimplifyPersonName]
(@str NVARCHAR (MAX))
RETURNS NVARCHAR (MAX)
AS
 EXTERNAL NAME [AssemblyName].[UserDefinedFunctions].[SimplifyPersonName];
GO

CREATE TABLE [per].[Person](
    [person_id] UNIQUEIDENTIFIER NOT NULL,
    [family_name] NVARCHAR(64) NULL,
    [given_name] NVARCHAR(64) NULL,
    [given_name_simple]  AS ([per].[SimplifyPersonName]([given_name])),
    [family_name_simple]  AS ([per].[SimplifyPersonName]([family_name])),
 CONSTRAINT [PK_Person] PRIMARY KEY CLUSTERED ([person_id] ASC)
);
GO

CREATE NONCLUSTERED COLUMNSTORE INDEX [CSIX_Person] ON [per].[Person]
(
    [person_id],
    [family_name],
    [given_name]    
)WITH (DROP_EXISTING = OFF, COMPRESSION_DELAY = 0) ON [INDEX]
GO

SELECT COUNT(p.person_id)
FROM per.Person p
WHERE (SUBSTRING(UPPER(p.[family_name_simple]),1,1)) <= N'Z'


SQL Server Agent Job Notifications Not Working

$
0
0
We have successfully setup Database Mail, and I am able to right click and 'Send Test E-Mail' and it works perfect. We have a few jobs setup in SQL Server Agent, and if the job fails it should e-mail us. Recently a job failed, but no e-mail. So I looked at the job log and see:

NOTE: Failed to notify 'Development' via email.

I confirm under Operators we have `Development` with the e-mail address I would like the error message to go to. Any ideas what would cause this?

SQL CTE with 8 million rows and PIVOT

$
0
0
--Trying to see if there is a better way of handling this SQL code.  This view will be leveraged in a Power BI report but we are trying to query over 8 million rows and never returns.  We have added indexes but still no luck. How can this view be optimized or rewritten? 


ALTER VIEW [dbo].[vw_RawDataEntityReport]
AS 
WITH CTE_Rawdata
AS (SELECT AG.[Name] AS [Account Group],
           ACC.Id AS [Account ID],
           ACC.[Name] AS [Account Description],
           CASE
               WHEN ACD.IsForBeginningOfYearForTaxCalculation = 1 THEN
                   'B'
               ELSE
                   'E'
           END AS [Beginning/Ending],
           ACD.Amount,
           CASE
               WHEN J.IsIncludedInEverywhereTotal = 1 THEN
                   ACD.Amount
               ELSE
                   0
           END AS Amount2,
           J.StateId AS JurisdictionName,
           FP.TaxYearId AS [Tax Year],
           FP.[Name] AS [Short Year],
           LE.SourceEntityId AS [Display Entity ID],
           LE.[Name] AS [Entity Name],
           CAST(LE.SourceEntityId AS VARCHAR(20)) + '-' + LE.[Name] AS [Entity]
    FROM SWP.AccountData ACD
        LEFT JOIN SWP.Account ACC
            ON ACC.Id = ACD.AccountId
        LEFT JOIN SWP.AccountGroup AG
            ON AG.Id = ACC.AccountGroupId
        LEFT JOIN SWP.FilingDecision FD
            ON FD.Id = ACD.FilingDecisionId
        LEFT JOIN SWP.Jurisdiction J
            ON J.Id = FD.JurisdictionId
        LEFT JOIN SWP.FilingPeriod FP
            ON FP.Id = FD.FilingPeriodId
        LEFT JOIN SWP.LegalEntity LE
            ON LE.Id = FD.LegalEntityId)
SELECT [Account Group],
       [Account ID],
       [Account Description],
       [Tax Year],
       [Short Year] AS [Filing Period],
       [Display Entity ID],
       [Entity Name],
       [Entity],
       [Beginning/Ending],
       [EV],
       [AL],
       [AK],
       [AZ],
       [AR],
       [CA],
       [CO],
       [CT],
       [DE],
       [DC],
       [FL],
       [GA],
       [HI],
       [ID],
       [IL],
       [IN],
       [IA],
       [KS],
       [KY],
       [LA],
       [ME],
       [MD],
       [MA],
       [MI],
       [MN],
       [MS],
       [MO],
       [MT],
       [NE],
       [NV],
       [NH],
       [NJ],
       [NM],
       [NY],
       [NYC],
       [NC],
       [ND],
       [OH],
       [OK],
       [OR],
       [PA],
       [RI],
       [SC],
       [SD],
       [TN],
       [TX],
       [UT],
       [VT],
       [VA],
       [WA],
       [WV],
       [WI],
       [WY],
       [RQ],
       [OT],
       [O1],
       [O2],
       [O3],
       [O4]
FROM
(
    SELECT CTRD.[Account Group],
           CTRD.[Account ID],
           CTRD.[Account Description],
           CTRD.[Tax Year],
           CTRD.[Short Year],
           CTRD.[Display Entity ID],
           CTRD.[Entity Name],
           CTRD.[Entity],
           CTRD.[Beginning/Ending],
           CTRD.JurisdictionName,
           SUM(Amount) AS Amount
    FROM CTE_Rawdata CTRD
    GROUP BY CTRD.[Account Group],
             CTRD.[Account ID],
             CTRD.[Account Description],
             CTRD.[Tax Year],
             CTRD.[Short Year],
             CTRD.[Display Entity ID],
             CTRD.[Entity Name],
             CTRD.[Entity],
             CTRD.[Beginning/Ending],
             CTRD.JurisdictionName
    UNION ALL
    SELECT CTRD.[Account Group],
           CTRD.[Account ID],
           CTRD.[Account Description],
           CTRD.[Tax Year],
           CTRD.[Short Year],
           CTRD.[Display Entity ID],
           CTRD.[Entity Name],
           CTRD.[Entity],
           CTRD.[Beginning/Ending],
           'EV' AS JurisdictionName,
           SUM(Amount2) AS Amount
    FROM CTE_Rawdata CTRD
    GROUP BY CTRD.[Account Group],
             CTRD.[Account ID],
             CTRD.[Account Description],
             CTRD.[Tax Year],
             CTRD.[Short Year],
             CTRD.[Display Entity ID],
             CTRD.[Entity Name],
             CTRD.[Entity],
             CTRD.[Beginning/Ending]
) A
PIVOT
(
    SUM(A.Amount)
    FOR JurisdictionName IN ([EV], [AL], [AK], [AZ], [AR], [CA], [CO], [CT], [DE], [DC], [FL], [GA], [HI], [ID], [IL],
                             [IN], [IA], [KS], [KY], [LA], [ME], [MD], [MA], [MI], [MN], [MS], [MO], [MT], [NE], [NV],
                             [NH], [NJ], [NM], [NY], [NYC], [NC], [ND], [OH], [OK], [OR], [PA], [RI], [SC], [SD], [TN],
                             [TX], [UT], [VT], [VA], [WA], [WV], [WI], [WY], [RQ], [OT], [O1], [O2], [O3], [O4]
                            )
) AS pivotted

Connecting to SQL Server without instance name

$
0
0
This is probably something basic I'm overlooking, but... I have a 2017 database engine on a named instance with non-default port.  So connection string should be ServerName\InstanceName, xxxx.  I can connect from a remote Management Studio without providing instanceName - just ServerName, xxxx.  I noticed SQL Browser was running, so I disabled it.  however, I can still connect without InstanceName.  How do I ensure InstanceName is required in the connection?  Thanks.

high logical fragmentation on disk but the disk is 99% empty

$
0
0

hi, I'm not sure if its the right forum and if it is not the right one, please point me to the right forum.

I have a server with os 2012 R2 & SQL server 2012, used for small application with a little number of writes, so temp DB is very small and the transaction log is small also... 

the Tlog located in a different drive from the Data and the Temp DB is also in a different drive...

lately, I started to get warnings and errors from scom about 100% fragmentation in the logical disk, and when I entered the server I saw that drive T (TempDB) and drive L (Log) has 100% fragmentation in the "optimizing hard-drives", but when I looked inside of them I saw that the HD are 99% empty (for example from 10GB, only 100mb in use).

can someone explain to me what does this fragmentation means and how it is on 100% if the drive is 99 empty?

and I would like to know how to treat fragmentation on SQL server's drives, can it affect the SQL? do I need to ignore it? and what about the task of Microsoft doing defrag in the task scheduler, if it is not affecting the SQL, so can I do it also without fear of destroying the SQL?

How to add new db to existed maintenance plan

$
0
0

Hi,

I am using sql2014. Created transaction log backup back maintenance plan for some of the databses. now i would like to add one more new database to existing tlogbackup maintenance plan. 

when i tried edit the existed maintenance plan and selected the "these databses' but i am not able to see any database list in it. i am not able to understand what could be the issue.

please help how to add new databse to existed maintenanceplan.

Thanks,

Jo.


pols

Viewing all 15872 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>