Power Query数据源错误处理 – 如果出现错误,请跳过后续步骤。

huangapple go评论143阅读模式
英文:

Power Query Data Source error-handling - skip further steps if an error is encountered

问题

抱歉,由于文本中包含了特定于编程的代码部分,我将只提供非代码的内容翻译。以下是内容的翻译:

Good day

我有一个Power Query查询,它的数据源来自Sql.Database()查询。有时在拉取数据之前会删除核心表格,这会导致出现以下数据源错误:

DataSource.Error: Microsoft SQL: Invalid object name 'sqldb-prod.123_outcomes.1234_outcome'.. DataSourceKind = SQL. DataSourcePath = tcp:sqlsvr-prod.public.12345.database.windows.net, 3342;sqldb-reporting-prod. Message = Invalid object name 'sqldb-prod.123_outcomes.1234_outcome'.. ErrorCode = -2146232060. Number = 50000. Class = 16. . 引发异常的是IDbCommand接口。 表格:1234_example。

关于此问题,我的问题是是否可以添加一些IF或Try的M代码,以便它只生成一个空结果或空表格,并自动跳过后续的任何转换步骤?

我最不希望的是每天向客户发送一封失败消息的电子邮件(出现错误)。我理解错误并希望在代码中处理它。

非常感谢您提前的帮助。

英文:

Good day

I have a Power Query query that pulls its Source from a Sql.Database() query. Sometimes the core tables are dropped pre-pull which creates a Data Source error as follows:

> <ccon>DataSource.Error: <ccon>Microsoft SQL</ccon>: <ccon>Invalid object name 'sqldb-prod.123_outcomes.1234_outcome'.</ccon>. DataSourceKind = <ccon>SQL</ccon>. DataSourcePath = <ccon>tcp:sqlsvr-prod.public.12345.database.windows.net, 3342;sqldb-reporting-prod</ccon>. Message = <ccon>Invalid object name 'sqldb-prod.123_outcomes.1234_outcome'.</ccon>. ErrorCode = <ccon>-2146232060</ccon>. Number = <ccon>50000</ccon>. Class = <ccon>16</ccon>. </ccon>. The exception was raised by the IDbCommand interface. Table: 1234_example.

My question on this is whether there is some IF or Try otherwise M-code I can add so that it just generates a null outcome or empty table and that it automatically skips any transformation steps thereafter?

The last thing I want is an email to the customer daily with a failure message (error has occurred). I understand the error and would like to handle it in code.

Thanks in advance for the assistance.

答案1

得分: 1

你可以在 try otherwise 中包裹你的语句。下面的代码创建一个空表格。

otherwise
#table({},{})

还有 try...catch 的用法。

https://learn.microsoft.com/en-us/power-query/error-handling

但我不确定这会有多大帮助,因为没有基本表格被加载,而且下游的一切可能仍然会出问题。

英文:

You just wrap your statement in try otherwise. The code below creates an empty table.

try...
otherwise 
#table({},{}) 

There is also try...catch now too.

https://learn.microsoft.com/en-us/power-query/error-handling

I'm not sure how this will help though as no base table will be loaded and everything downstream will still presumably break.

huangapple
  • 本文由 发表于 2023年2月27日 16:26:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75578209.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定