I'm creating a application that should handle contacts, orders etc.
I want to distribute only the exe file and let the application take
care of creating and changing the database that is to be used.
Furthermore, I would also like to make it possible for the user to
select which sort of database to create and use, MSSQL, Oracel, Access
etc.
Is this possible? Or do I have distribute a databas file as well? My
first idea was to use OLEDB and let the user select which provider to
use, but I can't open a databas connection without a valid database
file.
Something simular to this..
Assume that the string aConnectionString would equal
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;User
Id=admin;Password=;"
or "Provider=sqloledb;Data Source=Aron1;Initial
Catalog=pubs;Integrated Security=SSPI;"
or "Provider=MySQLProv;Data Source=mydb;User
Id=UserName;Password=asdasd;"
OleDbConnection oConnection = new OleDbConnection(aConnectionString);
OleDbCommand oCommand = new OleDbCommand("create database
aDbName",oConnection);
oConnection.Open();
oCommand.ExecuteNonQuery();
oConnection.Close();
Br
Jonas 8 2126
Jonas,
Complete sample in VBNET below, it cannot be that hard to set that in C#
language.
I hope this helps?
Cor
Public Class Main
Public Shared Sub Main()
Dim catNewDB As New ADOX.Catalog
Dim fi As New IO.FileInfo("c:\db1.mdb")
If fi.Exists Then
If MessageBox.Show("Delete?", "Existing File db1.mdb", _
MessageBoxButtons.YesNo) = DialogResult.Yes Then
fi.Delete()
Else
Exit Sub
End If
End If
catNewDB.Create("Provider=Microsoft.Jet.OLEDB.4.0; " & "Data
Source=C:\db1.mdb")
'To make tables we use Adonet
Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;" &
_
" Data Source=C:\db1.mdb;User Id=admin;Password=;")
Dim cmd As New OleDb.OleDbCommand("CREATE TABLE persons ( " & _
"AutoId int identity ," & _
"Id int NOT NULL," & _
"Name NVarchar(50)," & _
"BirthDate datetime," & _
"IdCountry int," & _
"CONSTRAINT [pk_AutoId] PRIMARY KEY (AutoId)) ", conn)
conn.Open()
Try
cmd.ExecuteNonQuery()
Catch ex As OleDb.OleDbException
MessageBox.Show(ex.Message, "OleDbException")
Exit Sub
Catch ex As Exception
MessageBox.Show(ex.Message, "GeneralException")
Exit Sub
End Try
cmd = New OleDb.OleDbCommand("CREATE TABLE countries ( " & _
"AutoId int identity ," & _
"Id int NOT NULL," & _
"Name NVarchar(50)," & _
"CONSTRAINT [pk_AutoId] PRIMARY KEY (AutoId)) ", conn)
Try
cmd.ExecuteNonQuery()
Catch ex As OleDb.OleDbException
MessageBox.Show(ex.Message, "OleDbException")
Exit Sub
Catch ex As Exception
MessageBox.Show(ex.Message, "GeneralException")
Exit Sub
End Try
conn.Close()
End Sub
End Class
Cor
Patty,
Thanks normally I have above this sample
set a reference to COM adox ext 2.x for dll and security
That should be done for this.
That all.
Cor
There is a KB article showing how to pop up the Data Link Properties
dialog to let the user select the database connection: http://support.microsoft.com/default...b;EN-US;310083
--
Scott http://www.OdeToCode.com
On Fri, 27 Aug 2004 08:57:07 -0700, Patty O'Dors
<Pa********@discussions.microsoft.com> wrote: The more generic you make the SQL, the more likely it will be to work with all database providers. For instance, create table will work with either Oracle, SQL or Access - or pretty much anything else. But some functions like "IIf", "CStr" will only work with Access. Some things like clustered indexes will NOT work with Access. Some things will only work with MSSQL and nothing else, and some things will work with Oracle and nothing else. So if you want them to be able to choose, let them know which they can choose from, and make sure that you've tested it on *all* of those. Then at the start of the application, you can pop up a "database connection" dialog, (the purpose of which is to prompt the user for input and get back a connection string), similar to the one in the administrative tools\data sources applet in windows. How to do that is a subject for another post - I'm unsure as to how you do it exactly but I'm pretty sure you can do it without rolling your own.
Cor,
I tried the following code..
ADOX.Catalog catalog = new ADOX.CatalogClass();
catalog.Create(@"Provider=sqloledb;Data Source=Legolas;Initial
Catalog=Test;Integrated Security=SSPI;");
catalog.Create(@"Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=C:\mydb.mdb;User Id=admin;Password=;");
and only the second create works.. Is there any way to create a SQL
Server database or is there an error in the connectionstring?
I don't have access to a Oracel server so I havn't tested to create a
Oracel database.
Thanks!
Jonas
"Cor Ligthert" <no**********@planet.nl> wrote in message news:<uT**************@tk2msftngp13.phx.gbl>... Patty,
Thanks normally I have above this sample
set a reference to COM adox ext 2.x for dll and security
That should be done for this.
That all.
Cor
Is it possible to create new databases with the Data Link Properties
dialog or can you only select existing databases?
Scott Allen <bitmask@[nospam].fred.net> wrote in message news:<gp********************************@4ax.com>. .. There is a KB article showing how to pop up the Data Link Properties dialog to let the user select the database connection:
http://support.microsoft.com/default...b;EN-US;310083
-- Scott http://www.OdeToCode.com
On Fri, 27 Aug 2004 08:57:07 -0700, Patty O'Dors <Pa********@discussions.microsoft.com> wrote:
The more generic you make the SQL, the more likely it will be to work with all database providers. For instance, create table will work with either Oracle, SQL or Access - or pretty much anything else. But some functions like "IIf", "CStr" will only work with Access. Some things like clustered indexes will NOT work with Access. Some things will only work with MSSQL and nothing else, and some things will work with Oracle and nothing else. So if you want them to be able to choose, let them know which they can choose from, and make sure that you've tested it on *all* of those. Then at the start of the application, you can pop up a "database connection" dialog, (the purpose of which is to prompt the user for input and get back a connection string), similar to the one in the administrative tools\data sources applet in windows. How to do that is a subject for another post - I'm unsure as to how you do it exactly but I'm pretty sure you can do it without rolling your own.
Jonas,
This goes only for ms-Access, although you can discuss what is a database.
When there is an existing SQL server than you can of course use that Create
command to create a database in a existing SQL server.
I have understood that SQL express server will have in future posibilities
for easy installing.
I hope this helps?
Cor I tried the following code..
ADOX.Catalog catalog = new ADOX.CatalogClass(); catalog.Create(@"Provider=sqloledb;Data Source=Legolas;Initial Catalog=Test;Integrated Security=SSPI;"); catalog.Create(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\mydb.mdb;User Id=admin;Password=;");
Just select an existing database...
--
Scott
On 28 Aug 2004 07:30:11 -0700, jo***@bootman.se (Jonas L) wrote: Is it possible to create new databases with the Data Link Properties dialog or can you only select existing databases?
Scott Allen <bitmask@[nospam].fred.net> wrote in message news:<gp********************************@4ax.com>. .. There is a KB article showing how to pop up the Data Link Properties dialog to let the user select the database connection:
http://support.microsoft.com/default...b;EN-US;310083
-- Scott http://www.OdeToCode.com
On Fri, 27 Aug 2004 08:57:07 -0700, Patty O'Dors <Pa********@discussions.microsoft.com> wrote:
>The more generic you make the SQL, the more likely it will be to work with >all database providers. >For instance, >create table >will work with either Oracle, SQL or Access - or pretty much anything else. >But some functions like "IIf", "CStr" will only work with Access. >Some things like clustered indexes will NOT work with Access. >Some things will only work with MSSQL and nothing else, and some things will >work with Oracle and nothing else. >So if you want them to be able to choose, let them know which they can >choose from, and make sure that you've tested it on *all* of those. >Then at the start of the application, you can pop up a "database connection" >dialog, (the purpose of which is to prompt the user for input and get back a >connection string), similar to the one in the administrative tools\data >sources applet in windows. How to do that is a subject for another post - I'm >unsure as to how you do it exactly but I'm pretty sure you can do it without >rolling your own. > >
--
Scott http://www.OdeToCode.com
You will have to test your code with any database that you want to support.
If you don't have SQL Server or Oracle yourself, you will have a difficult
time doing this.
Frequently, when I install an app on SQL Server, the install instructions
require me to create the database myself. That is typical. If you want to
create the database yourself, you can always use SQL DMO, but it will
increase the size of your app (to include the DMO library) and you can only
install the app on the machine where SQL Server is actually hosted. This is
what you are actually doing when you use MSDE (the small free version of SQL
Server available from Microsoft).
Better option is to require the user to create the database themselves (with
no tables) and give you a working connection string.
HTH,
--- Nick
"Jonas L" <jo***@bootman.se> wrote in message
news:7b*************************@posting.google.co m... I'm creating a application that should handle contacts, orders etc. I want to distribute only the exe file and let the application take care of creating and changing the database that is to be used. Furthermore, I would also like to make it possible for the user to select which sort of database to create and use, MSSQL, Oracel, Access etc.
Is this possible? Or do I have distribute a databas file as well? My first idea was to use OLEDB and let the user select which provider to use, but I can't open a databas connection without a valid database file.
Something simular to this..
Assume that the string aConnectionString would equal "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;User Id=admin;Password=;" or "Provider=sqloledb;Data Source=Aron1;Initial Catalog=pubs;Integrated Security=SSPI;" or "Provider=MySQLProv;Data Source=mydb;User Id=UserName;Password=asdasd;"
OleDbConnection oConnection = new OleDbConnection(aConnectionString); OleDbCommand oCommand = new OleDbCommand("create database aDbName",oConnection); oConnection.Open(); oCommand.ExecuteNonQuery(); oConnection.Close();
Br Jonas This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: lkrubner |
last post by:
I have a webserver through Rackspace. I create a domain. I create an
FTP user. I upload some files. I create a database called
testOfSetupScript and then I create a database user named setup.
I...
|
by: Melissa |
last post by:
I have a frontend file named CustomerApp and backend file named CustomerData.
CustomerApp is at C:\Customer Database and CustomerData is at S:\Customer
Database. Could someone help me with the code...
|
by: dog |
last post by:
I've seen plenty of articles on this topic but none of them have been
able to solve my problem.
I am working with an Access 97 database on an NT4.0 machine, which has
many Access reports.
I...
|
by: Jonas L |
last post by:
I'm creating a application that should handle contacts, orders etc.
I want to distribute only the exe file and let the application take
care of creating and changing the database that is to be...
|
by: tommie.nygren |
last post by:
I am using Visual Studio.NET 2003 Enterprise Architect Edition
(according to my IT guy... how do I actually check what version of it I
am using?) and SQL Server Developer Edition (8.00.194 for you...
|
by: Paw |
last post by:
Greetings.
I use asp.
what I need is is when a visitor comes to the site, I need it to check
the host name. if "www.hometowndigest.com" is the host, then check a
folder named "something" and if...
|
by: etuncer |
last post by:
Hello All,
I have Access 2003, and am trying to build a database for my small
company. I want to be able to create a word document based on the data
entered through a form. the real question is...
|
by: Mich |
last post by:
Hi,
i'm building an web application for anonymous users. They can take a look in
the website, nothing more. In order to perform other actions, the anonymous
user must be logged. So i create an...
|
by: DeanL |
last post by:
Hi guys,
Does anyone know of a way to create multiple tables using information
stored in one table? I have a table with 4 columns (TableName,
ColumnName, DataType, DataSize) and wanted to know...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |