函数conectar a BD SQL Server(sqlconection)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了函数conectar a BD SQL Server(sqlconection)相关的知识,希望对你有一定的参考价值。

Conexión a base de datos con los parametros que llega del contructor
  1. Imports System
  2. Imports System.IO
  3. Imports System.Text
  4. Imports System.Data
  5. Imports System.Data.SqlClient
  6.  
  7. Public Class DBSQLServer
  8.  
  9. #Region "Properties"
  10. Private con As New SqlConnection
  11. Private cmd As New SqlCommand
  12. Private reader As SqlDataReader
  13. Private da As SqlDataAdapter
  14.  
  15. Public Property StringConnection As String = ""
  16. Public Property Host() As String
  17. Public Property DBName() As String
  18. Public Property User() As String
  19. Public Property Pass() As String
  20. Public Property Port() As String = 3306
  21.  
  22. #End Region
  23.  
  24. #Region "Constructores"
  25. Public Sub New(ByVal host As String, ByVal user As String, ByVal pass As String, ByVal DBName As String, ByVal Port As String)
  26. Me.Host = host
  27. Me.User = user
  28. Me.Pass = pass
  29. Me.DBName = DBName
  30. Me.Port = Port
  31. End Sub
  32.  
  33. Public Sub New(ByVal host As String, ByVal user As String, ByVal pass As String, ByVal DBName As String)
  34. Me.Host = host
  35. Me.User = user
  36. Me.Pass = pass
  37. Me.DBName = DBName
  38. End Sub
  39.  
  40. Public Sub New(ByVal strConnection As String)
  41. Me.StringConnection = strConnection
  42. End Sub
  43.  
  44. #End Region
  45.  
  46. #Region "Functions"
  47. ''' <summary>
  48. ''' conexion a la base de datos segun los parametros de constructor.
  49. ''' </summary>
  50. ''' <returns></returns>
  51. ''' <remarks></remarks>
  52. Private Function conecctedDB() As SqlConnection
  53. Try
  54. If (Me.StringConnection.Trim().Length > 0) Then
  55. Me.con = New SqlConnection(Me.StringConnection)
  56. Else
  57. Me.con = New SqlConnection(String.Format("Data Source={0}; Integrated Security=False; Id={1}; Password={2}; Catalog={3};", Me.Host, Me.User, Me.Pass, Me.DBName))
  58. End If
  59. Me.con.Open()
  60. Catch ex As SqlException
  61. Throw New System.Exception("Error de conexion a la basde de datos: (conectarBase)", ex)
  62.  
  63. End Try
  64.  
  65. Return Me.con
  66.  
  67. End Function
  68.  
  69.  
  70. #End Region
  71.  
  72. End Class

以上是关于函数conectar a BD SQL Server(sqlconection)的主要内容,如果未能解决你的问题,请参考以下文章

红色与公共汽车建筑联合会(Conectar a unidad de red y buscar archivos)

如何查询 SQL 表

我想要把sql serve2000的mdf ldf文件升级到能在sql2012中用 求大神帮忙转换

windows 2012服务器,sql serve 20112怎么开通1433端口

SQL serve 2008 r2安装失败,为啥?怎么办才好!!!!急急急!!!!

php连接sql serve后如何执行sql语句