Home Forums Programming Connecting Connecting to SQL Server from a Visual Studio 2012 Express Class RE: Connecting to SQL Server from a Visual Studio 2012 Express Class

  • Tim in this case, i'm not sure;

    I created a Simple Class library, and this is teh entire code, which compiles correctly in the full version of Visual Studio 2010;

    My project compiles no problem whether i go to Project>>Properties>>Compile>>Advanced Compile Objects, and i point it at any framework, 2.0, 3.5 or 4.0.

    Imports System.Data

    Imports System.Data.SqlClient

    Public Class Class1

    Private Sub x()

    'form a command that waits longer than 30 seconds for testing

    Dim sqlcmd As String = "WaitFor Delay '00:00:45';SELECT name FROM sys.tables;"

    Dim mySqlConnectionFormat As String = "data source={0};initial catalog={1};user id={2};password={3};Trusted_Connection=False;Connect Timeout=600;Application Name=GhostInTheMachine;"

    Dim MyConn As New SqlConnection

    MyConn.ConnectionString = String.Format(mySqlConnectionFormat, ".", "SandBox", "Noobie", "NotARealPassword")

    MyConn.Open()

    'now lets get a command object

    Dim mySqlCommand As New SqlCommand

    mySqlCommand.Connection = MyConn

    mySqlCommand.CommandTimeout = 600

    mySqlCommand.CommandType = CommandType.Text

    mySqlCommand.CommandText = sqlcmd

    Dim myDataReader As SqlDataReader

    myDataReader = mySqlCommand.ExecuteReader

    ' could either loop thru the reader itself, or stick it into a datatable .

    Dim MyDataTable As New DataTable

    MyDataTable.Load(myDataReader)

    'do something witht eh data?

    For Each dr As DataRow In MyDataTable.Rows

    Debug.Print(dr!name) ' [name] because i Know the column name from the query.

    Next

    End Sub

    End Class

    so my first question would be, on the developer machine you are fiddling with, do you have the .Net frameworks installed?

    look in C:\windows\Microsoft.NET\Framework, you should see multiple folders like this, representing each framework installed:

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!