New in SQL. Please help...

jotaeva

Member
Joined
Sep 2, 2009
Messages
8
Programming Experience
Beginner
I install Visual Studio 2005 and the version of SQL Express that comming with them. Allways I use Access DB but I need to understand and use SQL.

I don´t change nothing of the original installation. So, my problem is with this connection string:

VB.NET:
Me.con.ConnectionString = "Data Source=jvaf\sqlexpress;Initial Catalog=alumnos;User Id=sa;Password=;"

The error:

Login failed for user 'sa'. The user is not associated with a trusted SQL Server connection jvaf\sqlexpress.

Please, can me help about what is the correct User Id and password?
Thanks in advanced.
 
Judging by the Error Message you are getting, SqlExpress is using the Windows User Authentication system so you should try:
VB.NET:
"Data Source=jvaf\sqlexpress;Initial Catalog=alumnos;Integrated Security=True;User Instance=True"

this should allow access for the currently logged in Windows User.

Take a look at this page on www.connectionstrings.com, for further information. I highly recommend this site for all connection string problems.

Hope this helps. :)
 
Thanks. Confirmed: I use Windows Authentication but someting is wrong in my APP because persist the error. Now say:

Cannot open database "alumnos" requested by the login. The login failed. Login failed for user 'JVAF\Jorge Villamizar' \\.\pipe\7A197166-7F5F\tsql\query.

Can help me again? Thanks
 
Connection problem solved but now I try to insert a record and receive this error:

VB.NET:
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_meses_cursos". The conflict occurred in database "alumnos", table "dbo.cursos", column 'ID'.

I have 3 tables: cursos, meses and pagos related by the field ID. I don´t know if the problem is caused by a bad relation. The field type (ID) in the all the tables are exactly the same but in the the cursos (PK) is defined IDENTITY increment 1.

This is the actual code I use:

VB.NET:
Private Sub tbGrabar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbGrabar.Click
  vFecha = ""
  vFecha = txtInicio.Text
  vEdad = cbEdad.SelectedItem
  vGrupo = cbGrupo.SelectedItem
  vDia = cbDia.SelectedItem
  vHora = cbHora.SelectedItem
  mesactual()
  If txtNombre.Text = "" Or txtAcudiente.Text = "" Or vFecha = "" Or vGrupo = "" Or vHora = "" Or vDia = "" Or vEdad = "" Then
   MessageBox.Show("Nombre, Acudiente, Grupo, Hora, Inicio, Día o Edad no pueden estar en blanco", "Error en Grabación", 

MessageBoxButtons.OK, MessageBoxIcon.Warning)
   Exit Sub
  Else
   Try
    cmd = con.CreateCommand
    cmd.Connection = con
    cmd.CommandText = "INSERT into cursos 
(nombre,edad,colegio,inicio,grupo,dia,hora,acudiente,telof,telcel,telres,email,notas,saldo,total) values 
(@nombre,@edad,@colegio,@inicio,@grupo,@dia,@hora,@acudiente,@telof,@telcel,@telres,@email,@notas,0,0)"

    cmd.Parameters.Add("@Nombre", SqlDbType.VarChar, 50).Value = txtNombre.Text
    cmd.Parameters.Add("@edad", SqlDbType.VarChar, 10).Value = vEdad
    cmd.Parameters.Add("@colegio", SqlDbType.VarChar, 50).Value = txtColegio.Text
    cmd.Parameters.Add("@inicio", SqlDbType.VarChar, 50).Value = vFecha
    cmd.Parameters.Add("@grupo", SqlDbType.VarChar, 3).Value = vGrupo
    cmd.Parameters.Add("@dia", SqlDbType.VarChar, 10).Value = vDia
    cmd.Parameters.Add("@hora", SqlDbType.VarChar, 12).Value = vHora
    cmd.Parameters.Add("@acudiente", SqlDbType.VarChar, 50).Value = txtAcudiente.Text
    cmd.Parameters.Add("@telres", SqlDbType.VarChar, 20).Value = txtResidencia.Text
    cmd.Parameters.Add("@telof", SqlDbType.VarChar, 20).Value = txtOficina.Text
    cmd.Parameters.Add("@telcel", SqlDbType.VarChar, 20).Value = txtCelular.Text
    cmd.Parameters.Add("@email", SqlDbType.VarChar, 50).Value = txtEmail.Text
    cmd.Parameters.Add("@notas", SqlDbType.VarChar, 100).Value = txtNotas.Text
    cmd.ExecuteNonQuery()

    cmd = con.CreateCommand
    cmd.Connection = con
    cmd.CommandText = "INSERT into meses (id,nombre,monto,mesactual,status) values ('" & vUltimo & 
"',@nombre,@monto,@mesactual,'ACTIVO')"
    cmd.Parameters.Add("@Nombre", SqlDbType.VarChar, 50).Value = txtNombre.Text
    cmd.Parameters.Add("@monto", SqlDbType.Money, 20).Value = txtMensualidad.Text
    cmd.Parameters.Add("@mesactual", SqlDbType.VarChar, 12).Value = vMes
    cmd.ExecuteNonQuery()
    MessageBox.Show("Alumno Creado OK")
   Catch ex As Exception
    MessageBox.Show(ex.Message)
   End Try
  End If
  reset()
 End Sub
Can you help me?
 
Last edited:
Back
Top