Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: (untagged)
I want to create database and tables on the client system when i install the setup on it.For that i created a installation class and text file for the database creation.In the installer class am calling the sql.txt for creating database.The installer class requires 3 .dll files like,sqlserver.connectioninfo,sqlserver.smo and sqlserver.sdk.sfk like that .I gave these references thrgh browsing option of add reference in the visualstudio.These .dll i took from c/prgmfiles/sqlserver/mssql/sdk/assemblies........but on build it shows warnings like
 
Warning 3  Unable to find dependency 'MICROSOFT.SQLSERVER.SERVICEBROKERENUM' (Signature='89845DCD8080CC91' Version='11.0.0.0') of assembly 'Microsoft.SqlServer.Smo.dll'
D:\newser\newset\newset.vdproj newset
 
Warning 1  Unable to find dependency 'MICROSOFT.SQLSERVER.SQLCLRPROVIDER' (Signature='89845DCD8080CC91' Version='11.0.0.0') of assembly 'Microsoft.SqlServer.Management.Sdk.Sfc.dll'
D:\newser\newset\newset.vdproj newset
 
Warning 2  Unable to find dependency 'MICROSOFT.SQLSERVER.MANAGEMENT.SQLPARSER' (Signature='89845DCD8080CC91' Version='11.0.0.0') of assembly 'Microsoft.SqlServer.Smo.dll'
D:\newser\newset\newset.vdproj newset
am adding my installer class code here,
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;
using System.Reflection;
using System.IO;
using System.Data.SqlClient;
 

namespace newser
{
    [RunInstaller(true)]
    public partial class DBInstaller : Installer
    {
        System.Data.SqlClient.SqlConnection masterconnection = new System.Data.SqlClient.SqlConnection();
 

        private string logFilePath = "\\SetupLog.txt";
        public DBInstaller():base()
        {
 
            //This call is required by the Component Designer.
            //Add initialization code after the call to InitializeComponent
           
            InitializeComponent();
        }
        private string GetSql(string Name)
        {
            try
            {
 
                // Gets the current assembly.
                Assembly Asm = Assembly.GetExecutingAssembly();
 
                // Resources are named using a fully qualified name.
                Stream strm = Asm.GetManifestResourceStream(Asm.GetName().Name + "." + Name);
 
                // Reads the contents of the embedded file.
                StreamReader reader = new StreamReader(strm);
 
                return reader.ReadToEnd();
            }
            catch (Exception ex)
            {
                Log(ex.ToString());
                throw ex;
            }
        }
        private void ExecuteSql(string serverName, string dbName, string Sql)
        {
            string connStr = "Data Source=localhost;Initial Catalog=master ;Integrated Security=True";
            using (SqlConnection conn = new SqlConnection(connStr))
            {
                try
                {
                    Server server = new Server(new ServerConnection(conn));
                    server.ConnectionContext.ExecuteNonQuery(Sql);
                }
                catch (Exception ex)
                {
                    Log(ex.ToString());
                }
            }
        }
        protected void AddDBTable(string serverName)
        {
            try
            {
                // Creates the database and installs the tables.
                string strScript = GetSql("sql.txt");
                ExecuteSql(serverName, "master", strScript);
            }
            catch (Exception ex)
            {
                //Reports any errors and abort.
                Log(ex.ToString());
                throw ex;
            }
        }
 
        public override void Install(System.Collections.IDictionary stateSaver)
        {
            base.Install(stateSaver);
            Log("Setup started");
            AddDBTable(this.Context.Parameters["local"]);
 
        }
        public void Log(string str)
        {
            StreamWriter Tex;
            try
            {
                Tex = File.AppendText(this.logFilePath);
                Tex.WriteLine(DateTime.Now.ToString() + " " + str);
                Tex.Close();
            }
            catch
            { }
        }
        public override void Uninstall(IDictionary savedState)
        {
            base.Uninstall(savedState);
        }
        public override void Commit(IDictionary savedState)
        {
            base.Commit(savedState);
        }
        public override void Rollback(IDictionary savedState)
        {
            base.Rollback(savedState);
        }
 
       
    }
}
here database i set it directly,ie not thrgh customising..........i can change it.........
 
anyone please give the proper instruction...stucked due to this and am fresher...........one more thing my sql.txt contains only create tables......
 
plz answer me that wethr there is any problem in my installer class and reference also without using installer class how can i do my database creation?
 
rahul
Posted 16-May-12 22:04pm
Edited 16-May-12 22:13pm
(no name)498.5K
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 587
1 Sergey Alexandrovich Kryukov 479
2 Maciej Los 305
3 Mathew Soji 195
4 Afzaal Ahmad Zeeshan 170
0 OriginalGriff 7,356
1 Sergey Alexandrovich Kryukov 6,777
2 DamithSL 5,461
3 Manas Bhardwaj 4,916
4 Maciej Los 4,475


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 17 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100