segunda-feira, 18 de fevereiro de 2013
Erro no INSERT em tabela com campo IDENTITY
Ao tentar inserir um valor em uma tabela com campo identity diretamente, será necessário ligar o atributo identity_insert, e também informar explicitamente a lista de campos, ou seja, o comando a seguir, sem a lista explícita vai gerar o erro "An explicit value for the identity column in table 'table_name' can only be specified when a column list is used and IDENTITY_INSERT is ON";
INSERT nome_tabela VALUES (Valor1, Valor2, etc)
Pois neste caso é imperativo que se informa a lista de campos, deste jeito:
INSERT nome_tabela(Campo1, Campo2, etc) VALUES (Valor1, Valor2, etc).
Para ligar e desligar o atributo:
SET IDENTITY_INSER ON BANCO.DBO.TABELA ON|OFF
Não sei se a lista de campos é uma questão de versão do banco, mas no SQL Server 2008 foi necessário informá-la. Bom trabalho a todos.
sexta-feira, 8 de fevereiro de 2013
TNS Protocol Adapter Erro
[PT-BR]
Um dos motivos deste erro é que o sqlplus não consegue identificar o ORACLE_SID, e fica sem saber em qual Instância de banco efetuar o login.
A solução mais simples que achei na web para meu caso foi configurar a variável de ambiente citadas:
c:>set ORACLE_SID=
O nome da variável pode estar em qualquer combinação de caixa (alta, baixa ou mista).
[ENU]
One of the causes of this error is the fact that sqlplus cannot identify the oracle_sid value, and cannot decide which instance to log in.
The simpler solution I`ve found on the web for my actual case was to set up the environment variable cited above:
c:>set ORACLE_SID=
The variable name can be typed in any combination of case.
sábado, 6 de outubro de 2012
SQLServer Cannot connect to server
When you get the Cannot connect to , many things can be involved, but here is one which is related to a named instance. If you choose to install a named instance you must inform to SQL Server the instance you want to use. It would list them by design, but does not. So, you must remember to inform the name you gave it. See the previous post about Express instance issues for more details.
TITLE: Connect to Server
Cannot connect to (local).
------------------------------
ADDITIONAL INFORMATION:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 2)
TITLE: Connect to Server
Cannot connect to (local).
------------------------------
ADDITIONAL INFORMATION:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 2)
Express named instance issues
If you have just installed an instance of SQL Server Express, and used a Named instance instead of a Default instance, so you must remember that it will be mandatory to inform the instance name right after the Server name field when loggin in (see picture below), or in another situation, like creating a database via script. The path to the database changes from MSSQLSERVER to SQLEXPRESS.
Using a named instance, instead of default bring some little bit differences when using SQLServer
terça-feira, 19 de junho de 2012
Reporting services subscriptions on SQL Express
When trying to sign a report to be sent automatically via email, I received the following message: The "Signatures for reports" not supported in this edition of Reporting Services. Before any more detailed research I realized I was pointing to a server whose version was SQLServer Express. This version does not have SQLServer Agent, which is who controls the actions of scheduling and execution schedule, among other things, SQLServer. Thus, some attention solve the problem. It was enough to point to the production server, and it opened normally. If you also deal with different versions of SQL Server: stay tuned!
Google translation from original at Portuguese version.
Google translation from original at Portuguese version.
Assinaturas do Reporting services no SQL Express
Ao tentar assinar um relatório para envio automático via email, recebi a seguinte mensagem: O recurso "Assinaturas para relatórios" não tem suporte nesta edição do Reporting Services. Antes de qualquer pesquisa mais detalhada percebi que estava apontando para um servidor cujo SQLServer era a versão Express. Esta versão não possui SQLServer Agent, que é quem controla as ações de agendamento e execução programada, entre outras coisas, do SQLServer. Assim, um pouco de atenção resolve o problema. Bastou apontar para o servidor de produção e o serviço abriu normalmente. Se você também lida com diferentes versões do SQL Server: fique atento!
sexta-feira, 15 de junho de 2012
Explicitly set the length of the variables
I was working on a function wich should return me a due date for a billing system, when all of a suden, an error show up: I cannot convert a date in string to a datetime. An excerpt of the code is:
declare @mes varchar = cast(month(getdate()) as varchar),
@ano varchar = cast(year(getdate()) as varchar),
@dia varchar = cast(day(getdate()) as varchar);
select convert(smalldatetime, @ano + '.' + @mes + '.' + @dia , 102 ) -- Error here!!!
The result string from @ano + '.' + @mes + '.' + @dia was '2.6.15' (I am using the ANSI format, i.e. 102). I could figure out that issuing a simple select statement:
select @ano + '.' + @mes + '.' + @dia, cast(year(getdate()) as varchar)
The solution: explicitly set the length of the variables. Look down here:
declare @mes varchar(2) = cast(month(getdate()) as varchar),
@ano varchar(4) = cast(year(getdate()) as varchar),
@dia varchar(2) = cast(day(getdate()) as varchar);
Finally, the goes (back) on...
declare @mes varchar = cast(month(getdate()) as varchar),
@ano varchar = cast(year(getdate()) as varchar),
@dia varchar = cast(day(getdate()) as varchar);
select convert(smalldatetime, @ano + '.' + @mes + '.' + @dia , 102 ) -- Error here!!!
The result string from @ano + '.' + @mes + '.' + @dia was '2.6.15' (I am using the ANSI format, i.e. 102). I could figure out that issuing a simple select statement:
select @ano + '.' + @mes + '.' + @dia, cast(year(getdate()) as varchar)
The solution: explicitly set the length of the variables. Look down here:
declare @mes varchar(2) = cast(month(getdate()) as varchar),
@ano varchar(4) = cast(year(getdate()) as varchar),
@dia varchar(2) = cast(day(getdate()) as varchar);
Finally, the goes (back) on...
Assinar:
Postagens (Atom)