Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Database Access / March 2008



Tip: Looking for answers? Try searching our database.

Cannot insert records

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ricardo Furtado - 25 Mar 2008 11:57 GMT
I've converted code from my Visual Basic 2005 application that used microsoft
access 97 in order to use SQL Server 2005, but i'm having problems on saving
records. V.Basic gives me no errors but the record is not updated.

Dim strSQLInsert As String = "INSERT INTO Paciente (CodTerceiro,
Nome,DataNascimento,Sexo,Morada,Localidade,CodPostal,Telefone,Telemovel,PrimeiroNome,UltimoNome,NumeroProcesso,IdRaca) VALUES" & _
" ('" & strIdPaciente & "','" & strNomePaciente & "'," &
Format(datDataNascimento, "MM-dd-yyyy") & "" & _
",'" & chrSexo.ToString & "',' ',' ',' ','" & strTelefone & "','" &
strTelemovel & " '," & _
"'" & strPrimeiroNome & "','" & strUltimoNome & "','" & strProcesso & "'," & _
retornaIDRacaAPartirNomeRaca(strRaca) & ")"

oconnLigacao2 = New SqlConnection(m_Connection)
Dim dr2 As SqlCommand

dr2 = New SqlCommand(strSQLInsert, oconnLigacao2)
oconnLigacao2.Open()
dr2.CommandType = CommandType.Text
dr2.ExecuteNonQuery()
If oconnLigacao2.State <> ConnectionState.Closed Then
   oconnLigacao2.Close()
End If

I've renamed OleDBCommand to SqlCommand and OleDBConnection to
SqlConnection. When i use sqlDataReader, i can se the data in the rows but
when i'm just trying to create records this doesn't seem to work. Can you
help?

my thanks in advanced
Ricardo Furtado - 25 Mar 2008 12:25 GMT
Could it be because of the connection string?

Private m_Connection As String = "Data
Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Cefalometria.mdf;Integrated Security=True;Connect Timeout=30;User Instance=False"

I've already tryed to change
User Instance=False
to
User Instance=True
But it doesn't Work and at debug time, the following error is shown:
"Failed to generate a user instance of SQL Server due to a failure in
starting the process for the user instance. The connection will be closed"

> I've converted code from my Visual Basic 2005 application that used microsoft
> access 97 in order to use SQL Server 2005, but i'm having problems on saving
[quoted text clipped - 26 lines]
>
> my thanks in advanced
Ricardo Furtado - 25 Mar 2008 17:14 GMT
Ok, i solved the problem
The problem was in the connectionstring
this way, works fine:
Private m_Connection As String = "Data
Source=.\SQLEXPRESS;AttachDbFilename=C:\ProjectoCefalo\GestCeph\GestCeph\Cefalometria.mdf;Integrated
Security=True;MultipleActiveResultSets=True;Connect
Timeout=30;TrustServerCertificate=True;User Instance=False"
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.