im using : v.s 2003
sql server: 2000

im creating this vb application and i took a coding from the inter net which uses 2005 i only have one error that is it's not supported in v.s 2003 can some one help me how to solve this
my problem occurs in here and giving me the error " Name 'My' is not declared. "

masterConnection.ConnectionString = My.Settings.masterConnectionString

below is the hole code

Imports System.ComponentModel
Imports System.Configuration.Install
Imports System.IO
Imports System.Reflection
Imports System.Data.SqlClient
Imports System.Data

'<RunInstaller(True)> Public Class VbDeployInstaller
'Inherits System.Configuration.Install.Installer

'#Region " Component Designer generated code "

'Public Sub New()
' MyBase.New()

'This call is required by the Component Designer.
' InitializeComponent()

'Add any initialization after the InitializeComponent() call

' End Sub


<RunInstaller(True)> Public Class VbDeployInstaller
Inherits System.Configuration.Install.Installer

'#Region " Component Designer generated code "

'Public Class VbDeployInstaller


Dim masterConnection As New System.Data.SqlClient.SqlConnection

Public Sub New()
MyBase.New()

'This call is required by the Component Designer.
InitializeComponent()


'Add initialization code after the call to InitializeComponent

End Sub

Private Function GetSql(ByVal Name As String) As String
Try

' Gets the current assembly.
Dim Asm As [Assembly] = [Assembly].GetExecutingAssembly()

' Resources are named using a fully qualified name.
Dim strm As Stream = Asm.GetManifestResourceStream( _
Asm.GetName().Name + "." + Name)

' Reads the contents of the embedded file.
Dim reader As StreamReader = New StreamReader(strm)
Return reader.ReadToEnd()

Catch ex As Exception
MsgBox("In GetSQL: " & ex.Message)
Throw ex
End Try
End Function

Private Sub ExecuteSql(ByVal DatabaseName As String, ByVal Sql As String)
Dim Command As New SqlClient.SqlCommand(Sql, masterConnection)

'Initialize the connection, open it, and set it to the "master" database
masterConnection.ConnectionString = My.Settings.masterConnectionString
Command.Connection.Open()
Command.Connection.ChangeDatabase(DatabaseName)
Try
Command.ExecuteNonQuery()
Finally
' Closing the connection should be done in a Finally block
Command.Connection.Close()
End Try
End Sub


Protected Sub AddDBTable(ByVal strDBName As String)
Try
' Creates the database.
ExecuteSql("MerryMeeting", "CREATE DATABASE " + strDBName)

' Creates the tables.
ExecuteSql(strDBName, GetSql("sql.txt"))

Catch ex As Exception
' Reports any errors and abort.
MsgBox("In exception handler: " & ex.Message)
Throw ex
End Try
End Sub

Public Overrides Sub Install(ByVal stateSaver As _
System.Collections.IDictionary)

MyBase.Install(stateSaver)
AddDBTable(Me.Context.Parameters.Item("dbname"))
End Sub


'Installer overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Component Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Component Designer
'It can be modified using the Component Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

'#End Region

End Class

'My' is a feature added in .net 2.0. Visual Studio 2003 works with .net 1.1 i believe.
I would seriously recommend updating to a newer version of Visual Studio. There are many great features in the more recent releases of both VS and the .net framework. You can download the express version of VS2008 for free from Microsoft.

Alternatively, you could store your connection string in a variable rather than in the My.Settings file. But you will likely run into more errors in the future since .net is now on version 3.5 (with 4 in beta) and most code is written for the more recent versions.

but the thing is this is a project in my class i created it using 2003 so when i convert it in to 2005 it s giving me loads of errors so i dont have the time to re do it again im need to give this soon as possible

then go with the second option, create a variable to store your connection string and remove the My.Settings line. You can find a sample of SQL Server 2000 Connection strings here. Just replace masterConnection.ConnectionString = My.Settings.masterConnectionString with something like masterConnection.ConnectionString = "Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;" .

Also, please use CODE tags when posting code. It is very hard to read through your project when it is not correctly formatted : /

thanks for your help ryshad
and there another thing i need to as you
im using this as a installer class wich i m using in custom actions to install a database in the sql server when application is installing
i used the way you have mention and it does not genereates any errors
but when i m running the the msi at the last moment it gives me error saying
"In exception handler: sql server is does not exist or access denied"
and then rolls back
do you have an idea why this is happening

my sql server is running fine

have you enabled remote connections in Sql Server, have you set the ServerAddress and security details correctly in your connection string?

is there a way to automatically read the connection string so when im installing this in a another mechine it will take there details automatically
i thought that my.settings did that.

Nope, My.Settings stores the settings you add to it.
The link i sent you with sample conneciton strings should have had one that uses Integrated Secutiry. If you use that then you can add each machine to the databases security settings and they will authenticate using their windows login.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.