AKB Forums

Go Back   AKB Forums > Technical sections > Languages, Compilers and Interpreters
Home Register Blogs FAQ Members List Calendar Downloads Arcade Mark Forums Read

Languages, Compilers and Interpreters C,C++,C#,.NET,Java,PHP,Perl,SQL and more

Troubles when posting message? Click here! :: Проблемы с отправлением сообщения? Нажмите сюда!

Reply
 
LinkBack Thread Tools Display Modes
Old Apr 11, 2007, 13:14   #1
Младенец
 
Censor's Avatar
 
Join Date: Mar 2007
Location: Там жарко..
Posts: 45
Rep Power: 0
Reputation: 10
Send a message via ICQ to Censor Send a message via MSN to Censor
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 Images
 
__________________
Если тебе дают линованую бумагу, пиши поперек. (с)
Censor is offline   Reply With Quote Quote selected
Old Apr 12, 2007, 04:48   #2
Младенец
 
Censor's Avatar
 
Join Date: Mar 2007
Location: Там жарко..
Posts: 45
Rep Power: 0
Reputation: 10
Send a message via ICQ to Censor Send a message via MSN to Censor
Люди, эээ, что, совсем никто с таким не сталкивался?...
__________________
Если тебе дают линованую бумагу, пиши поперек. (с)
Censor is offline   Reply With Quote Quote selected
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHPBB, VB, MD5 :) poet Web Development 4 Dec 12, 2005 09:32
Mojno li v VB kod vstavit sql zapros serty Languages, Compilers and Interpreters 1 Jul 18, 2002 10:41
VB programers needed Taurus Jobs 1 Apr 24, 2002 05:58
Problem when VB dll is called through VC++ kamu Languages, Compilers and Interpreters 1 Nov 6, 2001 14:17


All times are GMT. The time now is 08:52.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
This board was founded on September 29, 2001
Powered by Viper Internet

Affordable Web Hosting | ParevNet

Buy text link