 |
|
 |
Very clearly stated the problem and given a direct solution helped to solve my problem without having to Google any further
|
|
|
|
 |
|
 |
thanks,
I want to add odbc link to a remote pc.
Is it possible to make it easily?
(sorry for my poor english)
|
|
|
|
 |
|
 |
I have the same problem with creating ODBC data sources with visal studio. Are there any solutions?
There is a problem with storing password, or anyone have any suggestions?
thanks
|
|
|
|
 |
|
 |
This is code for a VB.Net Console application to testing DSN creation.
Imports System.Runtime.InteropServices
Module Module1
Private Const ODBC_ADD_DSN = 1 '(use this to add a user DSN)
Private Const ODBC_CONFIG_DSN = 2 '(use this to configure a user DSN)
Private Const ODBC_REMOVE_DSN = 3 '(use this to remove a user DSN)
Private Const ODBC_ADD_SYS_DSN = 4 '(use this to add a system DSN)
Private Const ODBC_CONFIG_SYS_DSN = 5 '(use this to configure a system DSN)
Private Const ODBC_REMOVE_SYS_DSN = 6 '(use this to remove a system DSN)
Public Function SQLConfigDataSource(ByVal parent As Integer, _
ByVal request As Integer, ByVal driver As String, ByVal attributes As String) As Integer
End Function
Sub Main()
Dim attributes As String = "DSN=IHMSReporting" & Chr(0) & _
"DESCRIPTION=IHMS Reporting Database" & Chr(0) & _
"TRUSTED_CONNECTION=NO" & Chr(0) & _
"SERVER=JUPITER\IHMSReporting" & Chr(0) & _
"DATABASE=IHMSReporting" & Chr(0)
Dim retVal As Integer = SQLConfigDataSource(0, ODBC_ADD_SYS_DSN, "SQL SERVER" & Chr(0), attributes)
Debug.WriteLine(attributes.Replace(Chr(0), "|"))
Console.WriteLine(retVal)
Console.WriteLine("Enter to Exit")
Console.ReadLine()
End Sub
End Module
Dennis Bottaro
djb@pringle.com
Coding my way to the next Blue Screen
|
|
|
|
 |
|
 |
I am trying to read a CSV file using the following code..
string connectionString = @"Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ=" + tempFilePath;
OdbcConnection odbcConnection = new OdbcConnection(connectionString);
odbcConnection.Open();
//Load data using sql
string sql;
sql = "Select * From " + tempFileName + " where ID='ID:" + ID + "'" ;
OdbcDataAdapter da = new OdbcDataAdapter(sql, odbcConnection);
//Creating DataSet and Filling Data into Dataset DS
da.Fill(dtCIMExtract);
odbcConnection.Close();
The problem is that,if the data has trailing spaces, the spaces are being trimmed. How will I avoid this?
Thanks in advance,
Bhargava
|
|
|
|
 |
|
 |
I get the fundas but i don't know how to call the dsn dialog in the user application
yours,
vytheese
|
|
|
|
 |
|
 |
I have tried to create DSN for 'Microsoft Text Dirver' like
Passed the vales DSName="TestName";DBPath=@"C:\\"
return SQLConfigDataSource((IntPtr)0, 1,
"Microsoft Text Driver (*.txt;*.csv)\0",
"DSN=" + DSName + "\0DBQ=" + DBPath + "\0");
But the function always returns false
I am not able to create the DSN with the DSName and DBPath
Please suggest
Siva_2181
|
|
|
|
 |
|
 |
Replace DBQ with DefaultDir
|
|
|
|
 |
|
 |
This doesn't work for SQL Authentication. Both creating and editing a system dsn for SQL Server. Is there a way to get it to work for sql auth?
Thanks.
|
|
|
|
 |
|
 |
I have only tested this on MySQL and MS-Access databases. And it works fine on them.
Sure you used the ID and PASSWORD flags correct?
Or try the registry approach (see below) maybe that works.
|
|
|
|
 |
|
 |
This is what I have:
SQLConfigDataSource((IntPtr)0, 4, "SQL Server", "DSN=Test\0Description=Test\0Network=DBMSSOCN\0Trusted_Connection=No\0UID=sa\0PWD=pwd\0Server=serverName\0Database=SqlCollectionDB\0");
This is for creating the data source. This fails to create the dsn i.e. doesn't create it at all.
When I use Trusted_Connection=Yes it works fine. If I use Trusted_Connection=No but don't specify the UID and PWD --then it creates the dsn with sql auth but leaves the user and pwd blank because i did not specify it.
registry entries for ODBC.INI does not store the registry value for password--so I am not sure how I can go about using the registry settings for this.
Thanks
|
|
|
|
 |
|
 |
I'm pretty sure the user name and password is not stored for DSN's that don't use trusted connection. The ODBC config wizard only asks for a username and password so that it can connect to the datasource to get the tables and test the connection, but it does not store that information anywhere as far as I know.
I've always used the Trusted_Connection=No for SQL Server and specify the credentials when you make the connection.
Thanks
|
|
|
|
 |
|
 |
Hi,
I have the same problem i can't create dsn with username and password.
But i did tried to do this manually and i successed connecting to my databese (from a computer that do not have access to this my database).
Regarts,Rony
C# developer
|
|
|
|
 |
|
 |
hello Dear....
I have Some problem.....
Creating User DSN.....
SQLConfigDataSource((IntPtr)0, 1, "SQL Server", "DSN=Test\0Description=Test\0Network=DBMSSOCN\0Trusted_Connection=No\0UID=sa\0PWD=pwd\0Server=serverName\0Database=SqlCollectionDB\0");
Its Not generating DSN At all.....
If I m not specifying UID & PAssword then it generates DSN...
But UId Intiated with Admin .....
I wanna set to it to "sa" How can i???
Please Help Me.....
|
|
|
|
 |
|
 |
I'm facing a problem while adding System DSN for SQL server.
This is the code
-> SQLConfigDataSource(0&, ODBC_ADD_SYS_DSN, "SQL Server", strAttributes)
strAttributes = Server=test12 DATABASE=db1 DSN=testdb UID=test01 PWD=test01 DESCRIPTION=DSN Created Dynamically
But if I'm using the strAttributes as 'Server=test12 DATABASE=db1 DSN=testdb DESCRIPTION=DSN Created Dynamically it is working'. If we enabled the Trusted connection (Trusted_Connection=Yes) that also is fine. I couldn't set the UID and PWD through this function.
Can anyone help me...
|
|
|
|
 |
|
 |
cpg83 wrote: Can anyone help me...
No.
Seriously!
The application USING your ODBC-Connection is expected to supply username and password. You CAN'T configure it fixed into the ODBC-Connection.
Note, that you can't do it manually either!
People think they can, because they can enter userid/password in the configuration dialog. But this is only for the initial retrieval of the database-names, so they can choose one of them. But after you close the configuration, it FORGETS about the supplied username and password.
Actually, this is the intended behaviour!
Cheers
Axel Joester
|
|
|
|
 |
|
 |
Thank you for your reply I initially wasted 1 day but couldn't figure out whats happening now I can. Is there any work around for this problem cause in some apps we want to have the user intervention to be minimum.
Thank you
|
|
|
|
 |
|
 |
Hola
Para crear un DSN con autentificación de SQL Server deben de aplicar lo siguiente:
Public Declare Auto Function SQLConfigDataSource Lib "ODBCCP32.DLL" (ByVal hwndParent As Integer, ByVal fRequest As Integer, ByVal lpszDriver As String, ByVal lpszAttributes As String) As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dl As Long ' Valor devuelto por la función API
Dim sAttributes As String ' Aributos
Dim sDriver As String ' Nombre del controlador
Dim sDescription As String ' Descripción del DSN
Dim sDsnName As String ' Nombre del DSN
Const ODBC_ADD_SYS_DSN As Long = 4 ' Se creará un DSN de sistema
Const vbAPINull As Long = 0& ' Puntero NULL
Dim attributes As New StringBuilder
' Establecemos los atributos necesarios
sDsnName = "Reportes"
sDescription = "Reportes de AcceDer"
sDriver = "SQL Server"
sAttributes = "DSN=" & sDsnName & Chr(0)
sAttributes = sAttributes & "Description=" & sDescription & Chr(0)
sAttributes = sAttributes & "Database=AcceDer" & Chr(0)
sAttributes = sAttributes & "Server=(Local)" & Chr(0)
sAttributes = sAttributes & "Network=default" & Chr(0)
sAttributes = sAttributes & "address=default"
sAttributes = sAttributes & "Trusted_Connection=True" & Chr(0)
' Creamos el nuevo origen de datos de usuario especificado.
' Si deseamos que aparezca el cuadro de diálogo, tendremos que
' especificar la propiedad «hWnd» del formulario donde se realiza
' la llamada a la función API.
dl = SQLConfigDataSource(vbAPINull, ODBC_ADD_SYS_DSN, sDriver, sAttributes)
If dl Then
MsgBox("Se ha creado el DSN de sistema.")
Else
MsgBox("No se ha podido crear el DSN de sistema.")
End If
End Sub
Cabe mencionar que el DSN se creara con la autentificación de SQL tomada directamente del servidor de Base de Datos y el usuario asigando a la base de datos. Para esto tu servidor de base de datos debera estar configurado con autenficación mixta (SQL/WIN)
Suerte y espero que les sirva
|
|
|
|
 |
|
 |
I tried using this C# code and it works ok for what it is, but I really need it to add a system DSN on a remote box. Its an SQL Server DB and that DB is on another box. But I need this code to allow me to use your methods in that way. I've tried SO many ways and keep banging my head.
Thanks,
Derek
|
|
|
|
 |
|
 |
Hi,
Did you use the correct connection options? The example here uses the options for a Microsoft Access Database. The connection options for a SQL Server connection should be something like:
SQLConfigDataSource((IntPtr)0, 1, "SQL Server\0","DSN=" + DSName + "\0Server=ServerName\0Database=DatabaseName\0Uid=Admin\0pwd=\0");
|
|
|
|
 |
|
 |
This still doesn't work!!! using attributes we can add the connection with out the UID and pwd
asd
|
|
|
|
 |
|
 |
Hi there
Have you tested if the key HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI could do the same trick for you?
I guess it would be the same. If you're going to test it, please let me know.
=====================
Lars [Large] Werner
lars@werner.no
http://lars.werner.no
=====================
|
|
|
|
 |
|
 |
Hi Lars,
Indeed the result of using the registrykey would be the same. The code would be longer though.
Greetz
Bas.
|
|
|
|
 |