locked
SQL Express Data Connection RRS feed

  • Question

  • User-1314346660 posted

    Hi I am trying to write to a local SQL Express instance on my laptop.

    The rest of my form code is working ok and is deploying fine. Can someone please help me with the sql connection string please???!!!

    Code is below...Thanks so much and sorry in advance for being a total newbie (I am - this is project1)

    myconn = New SqlConnection("Provider=SQLNCLI10;Data Source=DESKTOP-NEG813P\SQLEXPRESS;Initial Catalog=WebApplication1;Trusted_Connection = yes;")

    Monday, December 4, 2017 10:53 PM

Answers

  • User-335504541 posted

    <g class="gr_ gr_19 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation only-ins replaceWithoutSep" id="19" data-gr-id="19">Hi</g> Billson3000,

    I think you could set a breakpoint in your button click event.

    Then debug your code to check whether your code is executed or not.

    Does it your all code for this <g class="gr_ gr_303 gr-alert gr_spell gr_inline_cards gr_disable_anim_appear ContextualSpelling" id="303" data-gr-id="303">aspx</g> page?

    Best Regards,

    Billy

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 6, 2017 11:24 AM

All replies

  • User991499041 posted

    Hi Billson3000,

    Hi I am trying to write to a local SQL Express instance on my laptop.

    The rest of my form code is working ok and is deploying fine. Can someone please help me with the sql connection string please???!!!

    Code is below...Thanks so much and sorry in advance for being a total newbie (I am - this is project1)

    myconn = New SqlConnection("Provider=SQLNCLI10;Data Source=DESKTOP-NEG813P\SQLEXPRESS;Initial Catalog=WebApplication1;Trusted_Connection = yes;")

    You can define connection string in web.config 

    LocalDB Connection String Example

    <add name="ConnectionStringName"
        providerName="System.Data.SqlClient"
        connectionString="Data Source=(LocalDB)\v11.0;AttachDbFileName=|DataDirectory|\DatabaseFileName.mdf;
    InitialCatalog=DatabaseName;Integrated Security=True;MultipleActiveResultSets=True" />

    SQL Server Express Connection String Examples

    <add name="ConnectionStringName"
        providerName="System.Data.SqlClient"
        connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=DatabaseName;
        Integrated Security=True;MultipleActiveResultSets=True"/>

    then use following code

    Dim connectionString As String
    
      connectionString = ConfigurationManager.ConnectionStrings("ConnectionStringName").ToString

    SQL Server Connection Strings for ASP.NET Web Applications

    https://msdn.microsoft.com/en-us/library/jj653752(v=vs.110).aspx#localdb 

    Regards,

    zxj

    Tuesday, December 5, 2017 1:52 AM
  • User-335504541 posted

    <g class="gr_ gr_14 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation only-ins replaceWithoutSep" id="14" data-gr-id="14">Hi</g> Billson3000,

    myconn = New SqlConnection("Provider=SQLNCLI10;Data Source=DESKTOP-NEG813P\SQLEXPRESS;Initial Catalog=WebApplication1;Trusted_Connection = yes;")

    Please remove the Provider in your connection string.

    You could try to use vs to get the connection string:

    First, connect to your database in server explorer in vs.

    Then you right-click the database name, click the properties.

    Finally, you can get the connection string in the properties windows.

    Best Regards,

    Billy

    Tuesday, December 5, 2017 2:03 AM
  • User-1314346660 posted

    Hi Billy Liu,

    Thanks for replying. I have tried copying the connection string from with vs and pasting it straight in. I think this is a connection issue between vs and sql. I have even tried hooking this to an azure db with no luck there either. I would be really grateful if you could help. I am just starting out and trying to get my first project up and running!My code is:

    Imports System.Data.SqlClient

    Public Class WebForm1

    Inherits System.Web.UI.Page


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


    End Sub


    Protected Sub Button1_Click1(sender As Object, e As EventArgs)


    Dim myconn As SqlConnection


    Dim cmd As SqlCommand


    Dim sqlstring As String


    myconn = New SqlConnection("Data Source=DESKTOP-NEG813P\SQLEXPRESS;Initial Catalog=WebApplication1;Integrated Security=True;")


    myconn.Open()

    sqlstring = "INSERT INTO WebAppTable1 (Fname, Lname) values('" + FName.Text + "','" + LName.Text + "')"


    cmd = New SqlCommand(sqlstring, myconn)


    cmd.ExecuteNonQuery()

    myconn.Close()

    End Sub


    End Class

    Tuesday, December 5, 2017 4:00 PM
  • User-335504541 posted

    Hi Billson3000,

    I have tested your code, it works. What's the error do you meet?

    Best Regards,

    Billy

    Wednesday, December 6, 2017 1:43 AM
  • User-1314346660 posted

    Hi Billy,

    Great to meet you. Nice to hear from another Billy!

    The issue I am facing is that when I deploy the page, it loads fine and the two text boxes and submit button show on the page.

    I can then enter the data but when I press the button to submit the row to the database nothing happens. I have tried lots of variations on the connection string but nothing seems to work. That's SQL Express, SQL company server and SQL Azure private but none of them are accepting the update record.

    I would be eternally grateful if you could help. Once I can get a record submitted to the db I am on track and can get the web form to do all the other basic functions I need.

    Thanks

    Billy

    Wednesday, December 6, 2017 9:45 AM
  • User-335504541 posted

    <g class="gr_ gr_19 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation only-ins replaceWithoutSep" id="19" data-gr-id="19">Hi</g> Billson3000,

    I think you could set a breakpoint in your button click event.

    Then debug your code to check whether your code is executed or not.

    Does it your all code for this <g class="gr_ gr_303 gr-alert gr_spell gr_inline_cards gr_disable_anim_appear ContextualSpelling" id="303" data-gr-id="303">aspx</g> page?

    Best Regards,

    Billy

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 6, 2017 11:24 AM
  • User-1314346660 posted

    Thanks Billy. I have changed to C# and re-written the code. I have it working now. I think the real problem was the SQL insert but am working on a successful version now. Happy days and thank you again.

    Wednesday, December 6, 2017 8:01 PM