Click to See Complete Forum and Search --> : System Dsn (Crystal Report)


vivek_29
April 11th, 2001, 10:42 PM
Is there a way using which I can create system DSN from VB . I do not want the user of my application to create it.I know there is another way to do is by creating file DSN but in my situation i can not use file DSN basically I am using crystal reports 7.0 and to connect to database i want to use dsn.

So there are actualy two questions :
1) How can I create system DSN from vb?
2) How can I use file DSN in crystal Reports 7.0 ?

Cimperiali
April 12th, 2001, 02:06 AM
The great Lothar once answered this:
'--------
I don't know much about the RegisterDatabase call.
Fact is, the SQLConfigDataSource API supports creation of system DSNs.
sample:


Declare Function SQLConfigDataSource Lib "ODBCCP32.dll" ( _ byval h as Long, byval r as Long, byval strDriver as string, _ byval strattr as string) as Long
Declare Function SQLInstallerError Lib "ODBCCP32.dll" ( _ byval n as Long, byref r as Long, byval strError as string, _ byval lLen as Long, byref thelen as Long) as Long
public Sub cfg()
Dim s as strings = "DSN=LAH" & vbNullChar & "DATABASE=yourdb" & _ vbNullChar
& "SERVER=yourserver" & _ vbNullChar
If SQLConfigDataSource(0, 1, "SQL Server", s) = 0 then
MsgBox "no luck"
Dim r as Long
Dim strError as string
strError = string(255, " ")
Dim lLen as Long
SQLInstallerError 1, r, _
strError, 255, lLen
MsgBox strError
else
MsgBox "ok"
End If
End Sub

'and, in a second time:
how do you add or delete a DSN? SQLConfigDataSource?
its fRequest argument can take one of 3 values:
ODBC_ADD_DSN
ODBC_CONFIG_DSN for editing
ODBC_REMOVE_DSN

try the second one.
Personally, I usually delete and recreate a DSN.
'-----------





Special thanks to Lothar "the Great" Haensler. Come back soon, you Guru.

Cimperiali
April 12th, 2001, 02:09 AM
Whoops...
have a look:
http://codeguru.com/cgi-bin/bbs/wt/showpost.pl?Board=vb&Number=35258&page=&view=&sb=
as Iouri also suggested something great...


Special thanks to Lothar "the Great" Haensler. Come back soon, you Guru.