Armenian Knowledge Base  

Go Back   Armenian Knowledge Base > Technical sections > Languages, Compilers, Interpreters
Register

Reply
 
LinkBack Thread Tools
Old 11.04.2007, 14:14   #1
Младенец
 
Censor's Avatar
 
Join Date: 03 2007
Location: Там жарко..
Posts: 38
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default VB+MSSQL(проблема с подключением)

Значит так.
Есть функция Func(), которая делает запись в одну из таблиц некоей базы данных на
некоем сервере.
Так вот, когда эта функция включается в код простого приложения (одна WebForm, один
Button), то при нажатии на Button приложение исправно подключает базу и производит
запись.
Code:
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports System.io
Imports System.Runtime.InteropServices
Public Class WebForm1
    Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    End Sub
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object
    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) 
Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub
#End Region
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) 
Handles MyBase.Load
        'Put user code to initialize the page here
    End Sub
    Public Sub Func()
        Dim myConnectString As String = "Data Source=***;Initial Catalog=***;Persist 
Security Info=False;User ID=***;Password=***;packet size = 4096"
        Dim myConnection As New SqlConnection(myConnectString)
        'myConnection.Open()
        Dim sqlCommand As New SqlCommand
        Dim strSQL As String
        strSQL = "blablabla"
        sqlCommand.CommandText = strSQL
        sqlCommand.Connection = myConnection
        myConnection.Open()
        sqlCommand.ExecuteNonQuery()
 
    End Sub 
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles Button1.Click
        CreateSqlConnection()
    End Sub
End Class
Но когда та же функция включается в код приложения уже работающего с этой базой (на
основе взятых из нее данных создается отчет), то происходят странные, на мой взгляд
вещи.
WebConfig-и практически идентичные, во втором приложении лишь добавлены имя базы,
сервера и т.д., с ними работает CrystalReport.
Это кусок кода
Code:
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports System.io
Imports System.Runtime.InteropServices
 
Public Class WebForm2
    Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.SqlDataAdapter2 = New System.Data.SqlClient.SqlDataAdapter
        Me.SqlInsertCommand2 = New System.Data.SqlClient.SqlCommand
        Me.SqlConnection2 = New System.Data.SqlClient.SqlConnection
        Me.SqlSelectCommand2 = New System.Data.SqlClient.SqlCommand
        Me.cachedCrystalReport11 = New Porc.CachedCrystalReport1
        Me.cachedCrystalReport21 = New Porc.CachedCrystalReport2
        Me.crystalReport22 = New Porc.CrystalReport2
 
        .........
 
    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object
    'CODEGEN: This method call is
    'Do not modify it using the code editor.
 
    '''''''''''''''''''''''''''''''''''''''
#End Region
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) 
Handles MyBase.Load
        'Put user code to initialize the page here
        InitializeComponent()
    End Sub
    Public Sub Func()
        Dim myConnectString As String = "Data Source=***;Initial Catalog=***;Persist 
Security Info=False;User ID=***;Password=***;packet size = 4096"
        Dim myConnection As New SQLConnection(myConnectString)
        Dim sqlCommand As New SqlCommand
        Dim strSQL As String
        strSQL = "blablabla"
        sqlCommand.CommandText = strSQL
        sqlCommand.Connection = myConnection
        myConnection.Open()
        sqlCommand.ExecuteNonQuery()
    End Sub 
    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) 
Handles MyBase.Init
        Dim log As New TableLogOnInfo
        Dim ci As New ConnectionInfo
        ci.ServerName = ConfigurationSettings.AppSettings("server")
        ci.DatabaseName = ConfigurationSettings.AppSettings("database")
        ci.UserID = ConfigurationSettings.AppSettings("user")
        ci.Password = ConfigurationSettings.AppSettings("password")
        log.ConnectionInfo = ci
........
 
        CrystalReportViewer1.DataBind()
    End Sub
..........
End Class
Посмотрите, что делается с функцией, только-только включив ее, с чего бы это, не
понимаю..
Attached Thumbnails
prog1.jpg  
Reply With Quote
Old 12.04.2007, 05:48   #2
Младенец
 
Censor's Avatar
 
Join Date: 03 2007
Location: Там жарко..
Posts: 38
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default

Люди, эээ, что, совсем никто с таким не сталкивался?...
Reply With Quote
Reply

Thread Tools


На правах рекламы:
реклама

All times are GMT. The time now is 17:43.


Powered by vBulletin® Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.