Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello guys i have created a windows form application and now want to deploy its setup using installation shield and i want is to deploy application so that at user end he/she will be able to install by just click-->agree-->next-->Ok type setup which i am already willing to do but the problem is that how i add database to installer so that all the presets will work there at user end too...

by the way Sql server express edition installed at user end is in my requirement so its not the issue to run application without SQL server at user end as most people asked in many google search i have made...

I also have tried to google this problem but there they show simply how to deploy with database i.e. .mdf file

i have also find this very useful link.. CLICK ME

and tried

SQL
Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DB\pokerplayers.mdf; ;Integrated Security=True;User Instance=True"


and tried everything instructed there [including putting mdf file in bin directory] except one thing

SQL
string dbPath = Application.StartupPath + "\\Database1.mdf";


I don't know where to put above line of code??? anybody have any idea about this???
Posted
Updated 18-Jun-13 23:08pm
v2

if you want your sql server to be picked up locally

SqlConnection cn = new SqlConnection(@"Data Source=tcp:999.999.999.999;Initial Catalog= what ever;User ID=SA;Password=ILIKEPOOP");

and in sql self under your oject explorer go to security then login right click SA ... change password if you want to because its important to always know your password ... then on the lefthand side you wil see Select a page ... click on server roles make sure public and server admin is ticked

and under Securables tick what ever you want to use ... e.g connect SQL if you want to connect to the sql database and alter database if you want to be able to change things in database and so on
... if this is unclear just ask me on my email or reply to me il follow up
 
Share this answer
 
The AttachDbFileName attribute of your connection string should point to your .mdf file. So if you place your mdf file in the: INSTALLATION_PATH\DB\PokerPlayers.mdf, you can determine the installation path at runtime using Assembly.GetEntryAssembly().Location, than append the /DB/PokerPlayers.mdf to the retrieved value and used that to access the database.

Uros
 
Share this answer
 
Comments
Hitesh Rohilla 20-Jun-13 1:27am    
Thanks Koleraba for your reply but its not clear yet... can u show an example? as i am still confuse only on the part "where to put this database path in my code" here in your explanation you give a dynamic Assembly.GetEntryAssembly().Location to get run-time path but question remains same as its also database path so where to put this in my code.
You will need to specify the path of the database file when connecting to DBMS - when you will need to execute an operation on the database - something like:

C#
public void ExecuteDbOperation()
{
   var appDir = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
   var dbDir = System.IO.Path.Combine(appDir, "DB");
   var dbFilePath = System.IO.Path.Combine(dbDir, "PokerPlayers.mdf");
   var connectionString = string.Format(@"Server=SERVER_NAME\INSTANCE; AttachDbFilename={0};Database=Players; Trusted_Connection=True;", filePath);
   using(var conn = new SqlConnection(connectionString))
   {
      //Construct and execute a SqlCommand
   }
}

Hope that helps,
Uroš
 
Share this answer
 
Comments
Hitesh Rohilla 20-Jun-13 8:08am    
Many Thanks i think its helpful let me try this and then i will tell it works for me or have some more confusions...
Hitesh Rohilla 20-Jun-13 9:49am    
Koleraba I have tried your code but it says

"Keyword not supported: '.\sqlexpress; attachdbfilename'."

I also have doubt in your code that you have write "Database=Players" while our database file is "PokerPlayers.mdf" so does this mismatch works???
Hitesh Rohilla 20-Jun-13 9:54am    
also you have passed "filepath" on your connectionString but isn't it should be "dbFilePath"???
koleraba 20-Jun-13 10:51am    
Yes it should be dbFilePath. Sorry I was changing something after I copied it from VS and I guess I made a mistake. Database=Players specifies the initial catalog and not the name of the file you are attaching. If you don't know the name of the catalog, attach the file manually with SQL server management studio and take a look at the name of the database catalog. Since I didn't know the name of your DB catalog I just put in Players. Otherwise I tried the code and it worked OK for me. For more info on connection strings check the: http://www.connectionstrings.com/sql-server-2008
Hitesh Rohilla 20-Jun-13 19:08pm    
it don't work for me...

after doing further experiment i did this in my code

SqlConnection conn;
conn = new SqlConnection();
conn.ConnectionString = @"Server=.\SQLEXPRESS; Data Source="+Application.StartupPath + "\\Database.mdf;Integrated Security=True;";

also i tried to put full path

conn.ConnectionString = @"Data Source= C:\\Users\\Hitesh\\Desktop\\Database Connection Test\\Test2\\test2\\test2\\Database.mdf;Integrated Security=True; user Instance=True";


it gives me following error:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified).
Try the following:

Set your connection string to a standard one:
Server=COMPUTER_NAME\INSTANCE_NAME; Database=DATABASE; Trusted_Connection=True;

and replace the placeholders above with:

COMPUTER_NAME - The name of the computer running the SQL server or SQL server express.
INSTANCE_NAME - The name of the sql server instance. You can leave this blank if your are running unnamed sql server instance
DATABASE - The name of the database on the instance to which you are trying to connect to.

1. Make sure that your SQL server is installed on the machine which you are using for development(Server=.\SQLEXPRESS) specifies an sql server instance SQLEXPRESS on a localhost)

2. Make sure the name of your sql server instance actually is SQLEXPRESS and that it's service is up and running. You can check that using the SQL server configuration manager.

3. If you are not accessing a local SQL server make sure it's TCP/IP protocol is enabled. This can be done using the SQL server configuration manager tool.

When your code can successfully establish a connection to the server, modify the connection string to attach the required database as discused in a previous solution.
 
Share this answer
 
v2
Comments
Hitesh Rohilla 21-Jun-13 12:10pm    
all above mentioned checks i have done several times on many people suggestions and after that only i have post question here...

conn.ConnectionString = @"Server=.\SQLEXPRESS; Database=database; Trusted_Connection=True";

conn.ConnectionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=database;Integrated Security=True";

both above mentioned string work for me but only when database is present in Sql Server default location and created by that only. but if they will then how can i deploy database with click install ready setup??? i have no problem to connect database with standard string when created with SQL server manager...

so if i want to run it on user's computer i need to install sql express and restore my database there and then everything will be fine but that's the track i want to deploy an application setup with database so that at user end he/she don't need to restore database... he/she just need to install click>ok setup and everything should work...

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900