|
-
Nov 28th, 2000, 10:16 AM
#1
Thread Starter
Lively Member
My application has the need to create a new database file on its initial start up. I don't want the user to have to configure a DSN first. All access to the database will be via a 'DSN-less' conection. I have looked over the ado and dao object models and I haven't found a way to do this.
Any pointers?
Thanks
-
Nov 28th, 2000, 10:21 AM
#2
Member
Is this what your after ??
This example demonstrates different ways of using the ConnectionString property to open a Connection object. It also uses the ConnectionTimeout property to set a connection timeout period, and the State property to check the state of the connections. The GetState function is required for this procedure to run.
'BeginConnectionStringVB
Public Sub ConnectionStringX()
Dim cnn1 As ADODB.Connection
Dim cnn2 As ADODB.Connection
Dim cnn3 As ADODB.Connection
Dim cnn4 As ADODB.Connection
' Open a connection without using a Data Source Name (DSN).
Set cnn1 = New ADODB.Connection
cnn1.ConnectionString = "driver={SQL Server};" & _
"server=srv;uid=sa;pwd=pwd;database=Pubs"
cnn1.ConnectionTimeout = 30
cnn1.Open
' Open a connection using a DSN and ODBC tags.
Set cnn2 = New ADODB.Connection
cnn2.ConnectionString = "DSN=Pubs;UID=sa;PWD=pwd;"
cnn2.Open
' Open a connection using a DSN and OLE DB tags.
Set cnn3 = New ADODB.Connection
cnn3.ConnectionString = "Data Source=Pubs;User ID=sa;Password=pwd;"
cnn3.Open
' Open a connection using a DSN and individual
' arguments instead of a connection string.
Set cnn4 = New ADODB.Connection
cnn4.Open "Pubs", "sa", "pwd"
' Display the state of the connections.
MsgBox "cnn1 state: " & GetState(cnn1.State) & vbCr & _
"cnn2 state: " & GetState(cnn2.State) & vbCr & _
"cnn3 state: " & GetState(cnn3.State) & vbCr & _
"cnn4 state: " & GetState(cnn4.State)
cnn4.Close
cnn3.Close
cnn2.Close
cnn1.Close
End Sub
Public Function GetState(intState As Integer) As String
Select Case intState
Case adStateClosed
GetState = "adStateClosed"
Case adStateOpen
GetState = "adStateOpen"
End Select
End Function
'EndConnectionStringVB
See Also
Connection Object | ConnectionString Property | ConnectionTimeout Property | State Property
-
Nov 28th, 2000, 10:24 AM
#3
Thread Starter
Lively Member
close...
thats almost what im looking for =)
those are various ways of opening an existing database file. That I don't have a problem with =) I'm stuck on how to *create* the database file the first time the application starts up.
It should create a new database file and after its created I can add the tables/fields via SQL
thanks again
-
Nov 28th, 2000, 10:25 AM
#4
Addicted Member
Is there any difference between a blank ready-made (at design time) database and a new copy of that at initial startup?
-
Nov 28th, 2000, 02:52 PM
#5
Member
This can be done by automating Access, ie. create an Access Application object and then build the db through code. For something like a sql database it gets more tricky. Leave it with me. I'll try and dig out some old code and post it up in the next few days.
Let me know what type of db it is.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|