I Want vb6 code to attach sql server database So when any one install the program it works without need to attach database
and many thanks for all
Printable View
I Want vb6 code to attach sql server database So when any one install the program it works without need to attach database
and many thanks for all
No need for any Code .just package your exe and related database file .using Package and deployment wizard .see the following link for more detail.
http://msdn.microsoft.com/en-us/libr...(v=vs.60).aspx
firoz-raj Thank you for Reply But this project with SQL SERVER DATABASE AND Must be Attached SO That The Program Can Connect To It
Can you explain what you mean with attach a database?
Is there an SQL Server database already up and running and you need to connect to it?
Or do you need to do an install of SQL server and your application?
I need to do an install of SQL server and my application And the database file to be attached on the sql server from my vb6 code . so any one can install my program with sql express in the installation file and when he run program first time the database will be attached to the server
You can attach a database using a connection string (which you use in the normal way), such as this one:
Source: http://www.connectionstrings.com/sql-server/ , also contains this note:Quote:
Server=.\SQLExpress;AttachDbFilename=C:\MyFolder\MyDataFile.mdf;Database=dbname;Trusted_Connection=Yes;
Quote:
Why is the Database parameter needed? If the named database have already been attached, SQL Server does not reattach it. It uses the attached database as the default for the connection.
Can I Do This With VB6
I USE This Connection String
DataEnvironment1.Connection1.ConnectionString = "Provider=SQLOLEDB.1;OLE DB Services = -2 ;Password=Mypass;Persist Security Info=True; User ID=sa;Initial Catalog=DBNAME;Data Source = 192.168.0.1 "
change the connection string like the following .
Server=.\SQLExpress;AttachDbFilename=C:\MyFolder\MyDataFile.mdf;Database=dbname;Trusted_Connection=Y es;
Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;Database=dbname; Trusted_Connection=Yes;
si_the_geek : Is Your connection will be done with SQL Server 2000 , 2005 ,2008 and 2012
brother how it is wrong ?.Quote:
Yes, it may just be as simple as adding the part I highlighted to your current connection string.
I recommend you ignore firoz.raj's post, as he has (once again) posted something that he should know is wrong.
Server=.\SQLExpress;AttachDbFilename=C:\MyFolder\MyDataFile.mdf;Database=dbname;Trusted_Connection=Yes;
I'm not sure which versions support it (I'm fairly certain that 2008 onwards all do), so that is something you will need to research (there should be info on msdn.microsoft.com ) or find out by testing.
That part is wrong because it is an exact copy of what I posted (so you were just wasting the time of everybody who read it).
The other connection string you posted is wrong because it is for .Net rather than VB6