Solved

Running scripts from vb.net to Sql Server 2005 express

Posted on 2011-03-04
3
596 Views
Last Modified: 2012-05-11
vb.net 2008
sql server express sp4
running sql serve express on my one machine



I have a button on a form that executes this code:

Private Sub Button25_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button25.Click
        Dim connectionString As String = "Server=.\SQLEXPRESS;AttachDbFilename=C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Cart_Data.mdf;Initial Catalog=iCart_Data;Persist Security Info=True;User ID=sa;Password=veeger;Connect Timeout=0;User Instance=False"
        Dim conn As New SqlClient.SqlConnection(connectionString)
       
        conn.Open()

        ExecuteSQLScript("C:\Program Files\CrsEnt\Scripts\Truncate and shrink All Databases2.sql", conn)
       

        conn.Close()
        conn = Nothing
       
        MsgBox("Completed Updating Sql Server", MsgBoxStyle.Information)
    End Sub



The script is here:


USE [DESCMATCH]
GO
DBCC SHRINKFILE (DescMatch_Data, 100)
GO
DBCC SHRINKDATABASE ( 'DescMatch' ,NOTRUNCATE)
DBCC SHRINKDATABASE ( 'DescMatch' ,TRUNCATEONLY )
GO
use [DescMatchGisXref]
GO
DBCC SHRINKFILE (DescMatchGisXref, 100)
GO
DBCC SHRINKDATABASE ( 'DescMatchGisXref' ,NOTRUNCATE)
DBCC SHRINKDATABASE ( 'DescMatchGisXref' ,TRUNCATEONLY )

Problem:
I get a timeout error in .net but the process runs fine in sql server 2005 express.

I have set all the properties in sql server to not time out.


Thanks
fordraiders


0
Comment
Question by:fordraiders
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
devlab2012 earned 500 total points
ID: 35037055
have you tried CommandTimeout property of SqlCommand object e.g.
cmd.CommandTimeout = 120;
0
 
LVL 3

Author Comment

by:fordraiders
ID: 35037422
ok where exactly should I place it: from  here:

Dim cmd As New SqlClient.SqlCommand
        Dim Reader As System.IO.StreamReader

        Try
            cmd.CommandType = CommandType.Text
            cmd.Connection = conn

            Reader = New System.IO.StreamReader(Filename)
            Dim s As String = Reader.ReadToEnd
            s = Replace(s, "GO", "~") 'Replace GO with a "~". Split only works with char
            Dim delimiter() As Char = "~".ToCharArray
            Dim SQL() As String = s.Split(delimiter) 'Now split the different SQL statements into an array
            For I As Integer = 0 To UBound(SQL) 'Loop through array, executing each statement separately
                cmd.CommandText = SQL(I)
                cmd.ExecuteNonQuery()
            Next

            Reader.Close()
            Reader = Nothing
            cmd = Nothing

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 35037745
That worked Thanks !
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question