Insert data into db sql server

Asked

Viewed 83 times

1

I’m having problems connecting my project to the database, I do not understand the reason, I’ve looked at several tutorials, use sql server 2017, I can access db in an application, but the site is not working.imagem do erro

I’m using the following code

web config.

<connectionStrings>
<add name="SicConnectionString" connectionString ="Data Source=ETID-012312\\ETID012312;User=sa;Password=admin2312;Initial Catalog=Sic_db;Integrated Security=True;" providerName = "System.Data.SqlClient" />

cshtml. @{ Layout = "~/_Sitelayout.cshtml"; Page.Title = "Registration";

var fantasia = "";
var cnpj = "";
var cep = "";
var endereco = "";
var estado = "";
var cidade = "";
var bairro = "";
var celular = "";
var telefone = "";
var email = "";
var usuario = "";
var senha = "";
var csenha = "";
var error = false;
var resultado = "";

if (IsPost)
{
    var db = Database.OpenConnectionString("Data Source=;User=;Password=;Initial Catalog=;Integrated Security=True;");
    fantasia = Request.Form["fantasia_txv"];
    cnpj = Request.Form["cnpj_txv"];
    cep = Request.Form["cep_txv"];
    endereco = Request.Form["endereco_txv"];
    estado = Request.Form["estado_txv"];
    cidade = Request.Form["cidade_txv"];
    bairro = Request.Form["bairro_txv"];
    celular = Request.Form["celular_txv"];
    telefone = Request.Form["telefone_txv"];
    email = Request.Form["email_txv"];
    usuario = Request.Form["usuario_txv"];
    senha = Request.Form["senha_txv"];
    csenha = Request.Form["csenha_txv"];

    // Define the insert query. The values to assign to the
    // columns in the Product table are defined as parameters
    // with the VALUES keyword.

        var insertQuery = "INSERT INTO dbo.TempAcc (TA_fantasia, TA_cnpj, TA_cep, TA_endereco, TA_estado, TA_cidade, TA_bairro, TA_celular, TA_telefone, TA_email, TA_usuario, TA_senha)" +
            "VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11)";
        db.Execute(insertQuery, fantasia, cnpj, cep, endereco, estado, cidade, bairro, celular, telefone, email, usuario, senha);
        // Display the page that lists products.

}

}

can anyone tell me where am I missing? or a following template that works? ms tutorials did not work well.

1 answer

2


The problem is in your connection string

<connectionStrings>
<add name="SicConnectionString" connectionString ="Data Source=ETID-012312\\ETID012312;User=sa;Password=admin2312;Initial Catalog=Sic_db;Integrated Security=True;" providerName = "System.Data.SqlClient" />

Replace "User" attribute with "User ID"

  • I made this attempt, soon after the current error disappeared, but a new one appeared, Instance error, no other information.

  • Thanks for the help, I searched for a string that fits my code, and just as you quoted the "user" should have been exchanged for "user id", and as it is still in development and use a local instance, the "user id" and "password" do not need to be declared, my code works now, no.

  • It is not that they do not need to be declared, in which case you are authenticating through your login in windows and not in SQL Server.

  • that’s right, I’m learning about yet, so my confusion.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.