Foros del Web » Programación para mayores de 30 ;) » Programación General »

error en la conexión con la base

Estas en el tema de error en la conexión con la base en el foro de Programación General en Foros del Web. hola, hola!!! Tengo un programa en visual 6 que se conecta a una base de datos mediante ado. El problema es que debo crear la ...
  #1 (permalink)  
Antiguo 25/05/2004, 10:34
 
Fecha de Ingreso: mayo-2004
Ubicación: Valladolid (Spain)
Mensajes: 81
Antigüedad: 20 años
Puntos: 0
Pregunta error en la conexión con la base

hola, hola!!!

Tengo un programa en visual 6 que se conecta a una base de datos mediante ado.

El problema es que debo crear la cadena de conexión con los datos que me introducen en tres cuadros de texto.
Los cuadros de texto se llaman: TxtServidor, TxtUsuario, TxtContraseña.

Nunca me crea la conexión, siempre me da error de inicio de sesión con el usuario "<usuario>", pero ese usuario sí que tiene acceso al servidor y a la base.

Ah, en la cadena de conexión tampoco sé dónde colocar la contraseña.

Os enseño la cadena por si alguien puede echarme una mano:

Global connection As ADODB.connection 'Objeto connection
Set connection = New ADODB.connection

connection.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID='" & TxtUsuario.Text & "';Initial Catalog=CiclismoCYL;Data Source='" & TxtServidor.Text & "'"

Muchas gracias de todas formas

Un saludo
  #2 (permalink)  
Antiguo 25/05/2004, 16:55
Avatar de Avelar  
Fecha de Ingreso: noviembre-2002
Ubicación: Ensenada, Baja California, México
Mensajes: 673
Antigüedad: 21 años, 5 meses
Puntos: 1
Aquí tienes unos ejemplos de la ayuda de SQL Server con respecto a una conexión de ADO.
Código:
Examples
A. Using SQLOLEDB to connect to an instance of SQL Server: setting individual properties
The following Microsoft Visual Basic® code fragments from the ADO Introductory Visual Basic Sample show how to use SQLOLEDB to connect to an instance of SQL Server. 

' Initialize variables.
Dim cn As New ADODB.Connection
. . .
Dim ServerName As String, DatabaseName As String, _
   UserName As String, Password As String

' Put text box values into connection variables.
ServerName = txtServerName.Text
DatabaseName = txtDatabaseName.Text
UserName = txtUserName.Text
Password = txtPassword.Text

' Specify the OLE DB provider.
cn.Provider = "sqloledb"

' Set SQLOLEDB connection properties.
cn.Properties("Data Source").Value = ServerName
cn.Properties("Initial Catalog").Value = DatabaseName

' Decision code for login authorization type: 
' Windows NT or SQL Server authentication.
If optWinNTAuth.Value = True Then
    cn.Properties("Integrated Security").Value = "SSPI"
Else
    cn.Properties("User ID").Value = UserName
    cn.Properties("Password").Value = Password
End If

' Open the database.
cn.Open

B. Using SQLOLEDB to connect to an instance of SQL Server: connection string method
The following Visual Basic code fragment shows how to use SQLOLEDB to connect to an instance or SQL Server: 

' Initialize variables.
Dim cn As New ADODB.Connection
Dim provStr As String

' Specify the OLE DB provider.
cn.Provider = "sqloledb"

' Specify connection string on Open method.
ProvStr = "Server=MyServer;Database=northwind;Trusted_Connection=yes"
cn.Open provStr

C. Using MSDASQL to connect to an instance of SQL Server
To use MSDASQL to connect to an instance of SQL Server, use the following types of connections.

The first type of connection is based on the ODBC API SQLConnect function. This type of connection is useful in situations where you do not want to code specific information about the data source. This may be the case if the data source could change or if you do not know its particulars. 

In the code fragment shown, the ConnectionTimeout method sets the connection time-out value to 100 seconds. Next, the data source name, user ID, and password are passed as parameters to the Open method of the Connection object, using an ODBC data source named MyDataSource that points to the northwind database on an instance of SQL Server. The sa login ID is provided as the second parameter and the password is the third parameter.

Dim cn As New ADODB.Connection

cn.ConnectionTimeout = 100
' DSN connection. You can use variables for the parameters.
cn.Open "MyDataSource", "sa", "MyPassword"
' Alternative syntax follows:
' cn.Open "DSN=DataSourceName;UID=sa;PWD=Password;"

cn.Close

The second type of connection is based on the ODBC API SQLDriverConnect function. This type of connection is useful in situations where you want a driver-specific connection string. To make a connection, use the Open method of the Connection object and specify the driver, server name, user ID, password, and database. You can also specify any other valid keywords to include in the connection string. For more information about the keyword list, see SQLDriverConnect. 

Dim cn As New ADODB.Connection

' Connection to SQL Server without using ODBC data source.
cn.Open "Driver={SQL Server};Server=Server1;Uid=SA;Pwd=;Database=northwind"

cn.Close
__________________
Ariel Avelar
  #3 (permalink)  
Antiguo 26/05/2004, 10:40
 
Fecha de Ingreso: mayo-2004
Ubicación: Valladolid (Spain)
Mensajes: 81
Antigüedad: 20 años
Puntos: 0
Muchas gracias por tu ayuda Avelar.

He conseguido que funcione.

Graciassssssssssss
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 09:47.