0
I’m trying to run the Ddl command below that creates the table I need, but even not returning error the table is not created, would anyone have any idea where I’m going wrong?
public const string scriptCriacao = " if exists(select * from sys.objects as o where o.type =N'u' and o.name = N'Tuss_temp')"+
" drop table Tuss_temp "+
" Create Table Tuss_temp ( "+
" competencia nvarchar(30), "+
" codigoTerminologia float, "+
" nomeTerminologia nvarchar(256), "+
" codigoTermo nvarchar(30), "+
" termo nvarchar(256), "+
" dtInicioVigencia datetime, "+
" dtFimVigencia datetime, "+
" dtFimImplementacao datetime, "+
" tipoAcao nvarchar(256), " +
")";
String connectionString = "Data Source=1.1.1.1;Initial Catalog=PortalTISS_v3;Persist Security Info=True;User ID=sa;Password=teste";
SqlConnection SqlConn = new SqlConnection(connectionString);
SqlConn.Open();
SqlCommand cmd = new SqlCommand(scriptCriacao, SqlConn);
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
Make sure it’s not the missing server port in connectionString.
– Ismael
The connection is established I don’t think this is it, the problem is that I execute the command that does not return error, but does not effect the creation of the table
– Alexandre Souza
The solution was to separate the scripts as can be seen below
– Alexandre Souza
I replicated exactly your example, just by changing the connection string data and it worked perfectly. Another issue you should consider is bank access permissions for other applications.
– Ismael
public const string scriptDrop = " if exists(select * from sys.Objects as o Where o.type =N'u' and o.name = N'Tuss_temp')"+ " drop table Tuss_temp "; public const string scriptCreate = " Create Table Tuss_temp ( "+ " nvarchar competition(30), "+ " codigoTerminologia float, "+
" nomeTerminologia nvarchar(256), "+
" codigoTermo nvarchar(30), "+
" termo nvarchar(256), "+
" dtInicioVigencia datetime, "+
" dtFimVigencia datetime, "+
" dtFimImplementacao datetime, "+
" tipoAcao nvarchar(256), " +
")";
– Alexandre Souza
If possible, turn your comment into an answer and we will leave the question as solved. This is essential to make the "unanswered" queue fit.
– Ismael