Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i tried to make a simple program that store a name and password given by the user....i used sql server 2005 for the database....after the completion of the project i create a setup file and installed it in my friend's computer but it didn't work in that computer...
how can we make a database using program in c# that is compatible with any other computer....how can we create a database during the installation of the program...is it possible to make a dynamic connection string...loads of confusionsss...
Posted

It's not that simple: it depends on a number of factors:
1) What database did you use? If you used MySql or MS Sql, then it has to be installed where your friend can get at the server. This may mean installing it on his computer as well as your program.
Alternatively, if you only need a single user database, then you may get away with using SqlCE instead: it requires no installation other than that needed for .NET and is thus a lot easier to work with.
2) Where is the database? This will be related to (1) above, but if it is MySql or MsSQL then you will have to get your friend to identify the server that the database is on when you install the software, and possibly install the database on that server at teh same time.

Dynamic configuration strings are simple, it's working out what to put in them that is difficult! :laugh:
 
Share this answer
 
Comments
amsainju 5-Jun-11 10:00am    
i am using mssql server 2005...
my connectionstring is "Data Source=ARPAN-PC;Initial Catalog=dbtry;User ID=ARPAN;"
I Created a setup file for my program and installed the program in my friend's computer...i wanted to see if that installation would create a new database for the new installation in my friends computer...but it didn't created a new database also i check out the app.config file the conncetionstring was same as above given..
OriginalGriff 5-Jun-11 10:05am    
No, it won't create a new database! :laugh:
You will need to either create the database (with records if necessary) in your installation, if your friend has SQL Server installed, or get him to install it first. Then you can work out what the connection string will be: chances are the only common factor will be the "initial catalog"!
amsainju 5-Jun-11 10:10am    
yes my friends computer has the sql server installed in it...where can i get the tutorial for learning to create the database in the installation
OriginalGriff 5-Jun-11 10:15am    
:laugh:
Google and MSDN are always a good start:
http://www.google.co.uk/search?aq=f&sourceid=chrome&ie=UTF-8&q=create+database+during+installation
http://msdn.microsoft.com/en-us/library/49b92ztk(v=vs.71).aspx
amsainju 5-Jun-11 10:16am    
thank u...for the help :-)
Saying "but it didn't work" isn't getting you any help. Describe your problem, what you did, what error-messages you get... and people might be able to help you.


"how can we make a database using program in c# that is compatible with any other computer....how can we create a database during the installation of the program...is it possible to make a dynamic connection string."

Too unspecific for Q&A. Read the rules: "Be specific!"


"loads of confusionsss..."

Indeed.
 
Share this answer
 
Comments
amsainju 5-Jun-11 10:07am    
i have given the code i used to connect to the database....
i want my installation of the program to create a database for itself...i searched alot for the soln but i can't figure it out...the installion file of my program doesn't create the database and the connection string in the app.config file is still same as in my computer...i think it should change with the change in computer because the datasource changes with the computer..
please help me with this
thanks for your concern





using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace trydb.dll
{
class dllsqlhelper
{
public string getconstr()
{
string constr = System.Configuration.ConfigurationManager.ConnectionStrings["trydb"].ToString();
return constr;
}
public int insertUserInfo(string user, string pass)
{
// string res;
int i=0;
SqlConnection con = new SqlConnection();
con.ConnectionString = getconstr();
string sql = "insert into tbluser([username],[password]) values('" + user + "','" + pass + "')";
SqlCommand cmd = new SqlCommand(sql, con);
con.Open();
try
{
i = cmd.ExecuteNonQuery();
// res="sucess";
}
catch (Exception ex)
{
// res= "failure";
throw;

}
finally
{
con.Close();

}
return i;
}
}
}
When you have the SQL server up and running, you can import a backup of the working database on the new SQL server.

Alternative you use SQL statements to create new database[^] and tables[^] inside database.
 
Share this answer
 
Comments
amsainju 5-Jun-11 10:02am    
how can we create a new database using c#... the connectionstring requires the data source name
Kim Togo 5-Jun-11 10:27am    
No. You do not need to specify a database on connection string.
When no database is selected you need to change database or use to different connection strings
amsainju 5-Jun-11 11:29am    
do you have any example can you send it to me in amsainju@gmail.com
thanks for your support
Kim Togo 6-Jun-11 3:19am    
If you look at the links, there are some simple examples on how to create a database and tables.

http://www.w3schools.com/sql/sql_create_db.asp
http://www.w3schools.com/sql/sql_create_table.asp

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