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()
{
InitializeComponent();
}
private string GetSql(string Name)
{
try
{
Assembly Asm = Assembly.GetExecutingAssembly();
Stream strm = Asm.GetManifestResourceStream(Asm.GetName().Name + "." + Name);
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
{
string strScript = GetSql("sql.txt");
ExecuteSql(serverName, "master", strScript);
}
catch (Exception ex)
{
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