SQL Express Local and Remote database

did anyone try... are there any samples.. for this..

i would create aplication with local database, but in code on runtime it should change connection string and connect to remote database.... is this possible



Answer this question

SQL Express Local and Remote database

  • rd2h

    Oh found the answer on binding navigator in another post. Just disable the call to the actions in the designer and call the move next, move previous actions in the code itself after the check for blank fields.
  • Vijay TV

    Thanks shakalama but that does not seems to be what I am looking for.

    I did a quick test in my post earlier by modifying the setting file. I put the remote data source in the profile while keeping the local data source in the local tag. Published it and installed the application in the PC with the remote SQL express.

    Can't work. Still trying to refer to local database. So if it can't find the database, error.

    Guess I have to replace in the data source in the Setting before I published. But having the password in it is not the best solution since everyone who knows about the setting XML file will be able to see the password there. Guess it will have to do for now :(

    Vincent


  • jrmcdona

    Hi,

    Yes this is very possible. You can store your connection string externally (text file or registry) and just load it in your connection object. By that approach you can change the connection string even if its already compiled...





    cheers,

    Paul June A. Domag

  • ateens108


    I don't see why not. Just store it in the app.config as in the example from the article I posted.

  • karnayanar


    The Data Sources generated by the wizard are hard-wired to the connection strings in config file. I don't know whether you can change this programmatically at run time. At least it isn't obvious. This is also why I hate using data sources generated through the designer.

    I think the way to go is to create a new data source for your BindingSource when your app is not running locally. I'll see if I can locate a code example.



  • JasonPolycom

    1) Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True"

    2) Data Source=MyServer\SQLEXPRESS;Initial Catalog=D:\MyDataBase\RemoteDB.MDF;Persist Security Info=True;User ID=sa;Password=myPasswd

    If I Cut and Paste the second Data Source from above into the Settings, it is working. But that means the debugs is also using the remote link. When I open up the setting.xml file, I see the is a debug and one profile. Both looks similar. So if I replace the profile one to the remote and leave the debug one to the local, is that where the problem will be solved

    Vincent


  • jazman58


    What I usually do in this instance is create multiple connection string settings in my config file. In code I can determine which system my application is executing from at run time, for example local vs. web server, and then select the appropriate connection string setting.

  • KevCB226

    Use the app.config file and My.Settings to retrieve the connection string value. You should find an example in the below article:

    http://msdn.microsoft.com/library/default.asp url=/library/en-us/dnvs05/html/vbmysettings.asp



  • Sebastian Roth

    hi,

    i don't know much about sqlserver but i found this link and i think it might help you

    http://support.microsoft.com/default.aspx scid=304261

    hope this helps



  • vb help

    I am looking for the same idea. Say for local the connection string is "

    Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True"

    Now when debugging, I can use this link. But what if after package and setup with the one click installation and installed into another machine, I want the link to connect to remote database with this link:

    Data Source=MyServer\SQLEXPRESS;Initial Catalog=D:\MyDataBase\RemoteDB.MDF;Persist Security Info=True;User ID=sa;Password=myPasswd

    If that possible


  • TylEray

    I don't think I understand your question. Are you saying that you don't know how to change the connection string for your data source

    Could you post an example of how you are currently creating your data source connection It will be easier to consider a solution if we know what your code looks like.



  • Efren Molina

    This is just what I've been looking for... but can anyone show me a code sample on how to achieve this (or just a link...)


    Thanks
    LS

  • RichardWard

    I get the idea, so for my case I will do the following:

    Set myConn1 = local datasource
    Set myConn2 = remote datasource

    In code, check if local DB existed, else use remote DB. But the dataset is tied to the local DB, so how do you change that to the remote. A sample code will be good.

    Vincent

  • stubs

    Oh, I did not do much coding but use the Data source tab and recreate some using the wizard and then edit the dataset with the designer.

    Then I put the dataset into the forms with the binding navigator, adapters and so on.

    So I did not coding by creating a connection, command sql and so on. By the way, now I am trying to prevent the user from clicking add itm and leaving the fields blanks, use the binding navigator to move around which will cause an error. My fields does not accept NULL.

    If the user just click add item and then if leaving some fields blank and click save, I can I can check for blank fields, then if there is any blank, do not run the code

    Me.Validate()

    Me.BankBindingSource.EndEdit()

    Me.BankTableAdapter.Update(Me.Ds_bank.bank)

    But if the user click add item and then straight navigator away without filling all fields, the application will bomb.

    Vincent


  • SQL Express Local and Remote database