dcsimg
Results 1 to 24 of 24

Thread: Cannot connect to database

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2018
    Posts
    48

    Cannot connect to database

    Hello everybody,Can someone help me fix my issue i cannot login into database,I have an open source project and need to know how to connect to db this is the ConnectionDatabaselink.cs

    Code:
        class DatabaseConnectionLink
    {
        public string networkLink = "Server=" + Properties.Settings.Default["SQL_IP"] + ';' + "Database=" +
        Properties.Settings.Default["SQL_Database"] + ";" + "UID=" + Properties.Settings.Default["SQL_User"] + ';' + "PWD=" +
        Properties.Settings.Default["SQL_Pass"];
    
        public string networkLinkDatabaseList = "Server=localhost" + Properties.Settings.Default["SQL_IP"] + ';' + 
        "UID=" + Properties.Settings.Default["SQL_User"] + ';' + "PWD=" +
        Properties.Settings.Default["SQL_Pass"];
    
        public string networkTestLink = "Server=localhost" + Properties.Settings.Default["SQL_IP"] + ';'
        + "UID=" + Properties.Settings.Default["SQL_User"] + ';' + "PWD=" + Properties.Settings.Default["SQL_Pass"];
    
        public string networkLinkCreateDatabase = "Server=localhost" + Properties.Settings.Default["SQL_IP"] + ';' +
                "UID=" + Properties.Settings.Default["SQL_User"] + ';' + "PWD=" +
                Properties.Settings.Default["SQL_Pass"];
    }
    }

  2. #2

    Thread Starter
    Member
    Join Date
    Mar 2018
    Posts
    48

    Re: Cannot connect to database

    I dont know how to connect to my application and database,Please help me resolve this issue thank you verymuch.

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,675

    Re: Cannot connect to database

    You need to do some reading on ADO.NET. It seems like all you're doing there is creating a bunch of connection strings. To connect to a database you need to create an appropriate connection object with an appropriate connection string and call its Open method. For SQL Server, it would be a SqlConnection object. To do anything useful you need to create an appropriate command object with appropriate SQL and then execute it by calling ExecuteScalar, ExecuteReader or ExecuteNonQuery. For SQL Server, it would be a SqlCommand object.

    There's loads of information around about data access as it's one of the most common things that software does. If you have no idea at all then I can only assume that you haven't looked. Among the many resources available, you might follow the Database FAQ link in my signature below and check out some of the .NET data access resources available on this site. Most will be for VB.NET but the principles and types involved will be exactly the same for C#. There's also a link to a C# tutorial in my signature and that will cover data access in one of its chapters.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Member
    Join Date
    Mar 2018
    Posts
    48

    Re: Cannot connect to database

    Hmmm.I have an open source project and the mysql database as i can see is in bound with project.properties/settings ?
    So i just dont know how to connect to it,bcuz i usually work with other databases so ill need a little bit help. Do u want me to post the project with full source and u try to connect ? and then tell me the issue, it would be great thank u.

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,675

    Re: Cannot connect to database

    Quote Originally Posted by ali3nn View Post
    Hmmm.I have an open source project and the mysql database as i can see is in bound with project.properties/settings ?
    There is no "bound". As far as I can see, it's simply storing the connection string. A string is a string though, regardless of where you get it.
    Quote Originally Posted by ali3nn View Post
    So i just dont know how to connect to it,bcuz i usually work with other databases so ill need a little bit help.
    You connect to it exactly the same way. That's part of the point of ADO.NET: it works the same way regardless of the data source. You should download Connector/Net from MySQL, either as an installer or a NuGet package, and then you will have a MySQL-specific provider but everything else is the same, e.g. use a MySqlConnection where you might otherwise use a SqlConnection or an OleDbConnection.
    Quote Originally Posted by ali3nn View Post
    Do u want me to post the project with full source and u try to connect ? and then tell me the issue, it would be great thank u.
    I definitely don't want you to post the whole project. If you have specific code that you think should work but doesn't then post just that but if you have no idea at all then you need to do some research first. If you haven't searched the web for "c# mysql" or the like, I have to wonder why.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Member
    Join Date
    Mar 2018
    Posts
    48

    Re: Cannot connect to database

    I have researched everywhere,but still cannot fix it or i dont understand it, example when i run the project it shows me like in the pic
    Name:  error3.png
Views: 89
Size:  9.5 KB
    Name:  help2.png
Views: 89
Size:  9.7 KB

    My MYSQL Server Configuration
    Name:  mysql server configuration.jpg
Views: 88
Size:  22.6 KB

    Here is the Properties Settings of my project
    Name:  pik1.jpg
Views: 86
Size:  26.0 KB


    I dont know how to connect it, i already have MYSQL Workbench and i connect to it succesful but i cannot connect to my project,its an open source project i dont have database?
    So .. How to resolve the issue

  7. #7
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,675

    Re: Cannot connect to database

    Have you considered showing us the relevant code? How can we tell you what's wring with code we haven't seen? Also, have you looked at the actual value of the connection string you're using rather than just the code that constructs it?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Member
    Join Date
    Mar 2018
    Posts
    48

    Re: Cannot connect to database

    I have posted the source code of DatabaseLink.cs ?

  9. #9

    Thread Starter
    Member
    Join Date
    Mar 2018
    Posts
    48

    Re: Cannot connect to database

    Code:
        class DatabaseConnectionLink
    {
        public string networkLink = "Server=" + Properties.Settings.Default["SQL_IP"] + ';' + "Database=" +
        Properties.Settings.Default["SQL_Database"] + ";" + "UID=" + Properties.Settings.Default["SQL_User"] + ';' + "PWD=" +
        Properties.Settings.Default["SQL_Pass"];
    
        public string networkLinkDatabaseList = "Server=localhost" + Properties.Settings.Default["SQL_IP"] + ';' + 
        "UID=" + Properties.Settings.Default["SQL_User"] + ';' + "PWD=" +
        Properties.Settings.Default["SQL_Pass"];
    
        public string networkTestLink = "Server=localhost" + Properties.Settings.Default["SQL_IP"] + ';'
        + "UID=" + Properties.Settings.Default["SQL_User"] + ';' + "PWD=" + Properties.Settings.Default["SQL_Pass"];
    
        public string networkLinkCreateDatabase = "Server=localhost" + Properties.Settings.Default["SQL_IP"] + ';' +
                "UID=" + Properties.Settings.Default["SQL_User"] + ';' + "PWD=" +
                Properties.Settings.Default["SQL_Pass"];
    }
    }
    This is the database code that i have posted?

  10. #10
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    40,361

    Re: Cannot connect to database

    Quote Originally Posted by ali3nn View Post
    This is the database code that i have posted?
    That is just code to set up some strings.

    While they are connection strings (that are meant to be used as part of connecting to a database), they don't do any of the work of connecting - they are just used as part of the process.

    The actual code that matters is where you actually use those strings (networkLink etc), which you should be able to find using the Find features within Visual Studio.

  11. #11

    Thread Starter
    Member
    Join Date
    Mar 2018
    Posts
    48

    Re: Cannot connect to database

    Here is the app.config
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <configSections>
            <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
                <section name="Dental_Management_System.Properties.PaymentSettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
                <section name="Dental_Management_System.PaymentSettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
                <section name="Dental_Management_System.PaymentRates" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
                <section name="Dental_Management_System.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
            </sectionGroup>
        </configSections>
        <userSettings>
            <Dental_Management_System.Properties.PaymentSettings>
                <setting name="VATTax" serializeAs="String">
                    <value>12</value>
                </setting>
                <setting name="BIRnumber" serializeAs="String">
                    <value>222-222-222-222</value>
                </setting>
                <setting name="TINnumber" serializeAs="String">
                    <value>222-222-222-222</value>
                </setting>
                <setting name="TAXpermitIssueDate" serializeAs="String">
                    <value />
                </setting>
                <setting name="TAXpermitExpireDate" serializeAs="String">
                    <value />
                </setting>
            </Dental_Management_System.Properties.PaymentSettings>
            <Dental_Management_System.PaymentSettings>
                <setting name="VATTax" serializeAs="String">
                    <value>12</value>
                </setting>
            </Dental_Management_System.PaymentSettings>
            <Dental_Management_System.PaymentRates>
                <setting name="Cleaning" serializeAs="String">
                    <value />
                </setting>
                <setting name="Pasta" serializeAs="String">
                    <value />
                </setting>
                <setting name="Dentures" serializeAs="String">
                    <value />
                </setting>
                <setting name="Braces" serializeAs="String">
                    <value />
                </setting>
                <setting name="FixBrudge" serializeAs="String">
                    <value />
                </setting>
                <setting name="PullOut" serializeAs="String">
                    <value />
                </setting>
            </Dental_Management_System.PaymentRates>
            <Dental_Management_System.Properties.Settings>
                <setting name="SQL_IP" serializeAs="String">
                    <value />
                </setting>
                <setting name="SQL_Port" serializeAs="String">
                    <value />
                </setting>
                <setting name="SQL_User" serializeAs="String">
                    <value />
                </setting>
                <setting name="SQL_Pass" serializeAs="String">
                    <value />
                </setting>
                <setting name="SQL_Database" serializeAs="String">
                    <value>Dentalmanagment</value>
                </setting>
                <setting name="ShowBannerYesNo" serializeAs="String">
                    <value>False</value>
                </setting>
                <setting name="DoctorName" serializeAs="String">
                    <value>Doktor1</value>
                </setting>
                <setting name="DocAddress" serializeAs="String">
                    <value>Prishtine</value>
                </setting>
                <setting name="DocNumber" serializeAs="String">
                    <value>(02) 666-6666</value>
                </setting>
                <setting name="DocOfficeName" serializeAs="String">
                    <value>Default</value>
                </setting>
                <setting name="CalendarTest" serializeAs="String">
                    <value />
                </setting>
                <setting name="UseWAN" serializeAs="String">
                    <value>False</value>
                </setting>
                <setting name="WANDialogMsg" serializeAs="String">
                    <value>0</value>
                </setting>
                <setting name="HideConfigureButtonAtLogin" serializeAs="String">
                    <value>False</value>
                </setting>
                <setting name="UpgradeRequired" serializeAs="String">
                    <value>True</value>
                </setting>
                <setting name="LogoFileLocation" serializeAs="String">
                    <value />
                </setting>
                <setting name="UseDefaultLogo" serializeAs="String">
                    <value>True</value>
                </setting>
            </Dental_Management_System.Properties.Settings>
        </userSettings>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-6.9.9.0" newVersion="6.9.9.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
    <system.data>
        <DbProviderFactories>
          <remove invariant="MySql.Data.MySqlClient" />
          <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
        </DbProviderFactories>
      </system.data></configuration>

  12. #12
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,675

    Re: Cannot connect to database

    No one asked you for the app.config. What we are asking for - have asked for more than once - is the code that actually tries to connect to the database. If your attempt to connect is failing then you must have an actual attempt. Show us that code.

    Also, I said that you should look at the actual connection string(s) being used to connect, not just the code that constructs that connection string. I see no indication that you have done that. If your attempt to connect is failing then there's every chance that there's something wrong with your connection string so it is a no-brainer to actually look at that connection string.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  13. #13

    Thread Starter
    Member
    Join Date
    Mar 2018
    Posts
    48

    Re: Cannot connect to database

    I think this source uses connection with settings here is an pic ?
    Name:  settings.jpg
Views: 80
Size:  31.3 KB

  14. #14

    Thread Starter
    Member
    Join Date
    Mar 2018
    Posts
    48

    Re: Cannot connect to database

    I think this source uses connection with settings here is an pic ?
    Name:  settings.jpg
Views: 80
Size:  31.3 KB

  15. #15
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    40,361

    Re: Cannot connect to database

    That is still not the code.

    Please stop posting things other than what we have explicitly asked for... all you are doing is deliberately wasting our time, which is rather annoying (and that makes us less willing to give up our own time to help you).

    If you don't know how to find the code, see the end of post #10.

  16. #16
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,675

    Re: Cannot connect to database

    How is it possible that you are trying to write to connect to a database and yet you can't even identify the code that connects to the database? If you know that little about code and writing it then you need to spend much more time learning the basics of the language and data access in general. Until you can identify some existing code that connects to a database you are far from capable of even getting close to writing code to do it. It's not for us to teach you the basics. I'll offer nothing further until you show that you know enough at least to know what part of the code you need to provide to us to help you fix the problem.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  17. #17
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,958

    Re: Cannot connect to database

    This is one of the things I dislike about using the built-in wizard(s) to create typed datasets... they have a tendency to hide details like this... I suspect that's what's going on here... the OP has gone through the wizard, selected how they want to connect, entered the relevant info, and it's stored away in the config file and it instantly becomes a black box. Given the number of connection strings he has there, and how 3 our of 4 of them are pretty much the exact same thing, only the names are different, tells me that there's some code slinging going on...

    @ali3nn - what you need to do is search the code for where those 4 variables are used... at least one of them, if not all of them are used somewhere in the code... that's what the others are looking for... it maybe in your code, it may be in a .designer file... but it's going to be somewhere... you'll just need to search and find it.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  18. #18
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,675

    Re: Cannot connect to database

    @tg, actually, I don't think the wizard has been used here because, if it had, one of those settings would be type '(ConnectionString)' and have Application scope. The OP is constructing a connection string from parts in code so, for that connection string to be used anywhere, there must be code that creates a connection object and assigns the constructed connection string. The problem here is not the wizard but the lack of reading and learning by the OP.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  19. #19
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,958

    Re: Cannot connect to database

    hmmmmm.... true... that means there's even more code slinging going on than I thought.... bleh...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  20. #20
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,675

    Re: Cannot connect to database

    Actually, looking back at post #6, it does say:
    Connection test failed.
    so I wonder whether what's actually happening here is that the OP is trying to use the wizard and is clicking on the button that tests whether a connection can be made to the specified database. Of course, if that is the case then it would be nice if the OP were to actually explain that rather than assuming that we will just know exactly what they are doing via ESP or the like.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  21. #21

    Thread Starter
    Member
    Join Date
    Mar 2018
    Posts
    48

    Re: Cannot connect to database

    I think these 3 connection strings are these that i posted ?? i have to configure all of them ?

  22. #22
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,675

    Re: Cannot connect to database

    Good grief! This thread is utterly ridiculous. This is post #22 and you still have not displayed any indication that you have any clue what you're supposed to do. There may be a language barrier but that doesn't account for what's gone on here. We can help with issues but it's not for us to teach you how to program. If you have no idea how to connect to a database then go and learn. There's plenty of places you do that, including on this site, where I've already directed you. If you think you know how to do it then DO IT. If the code you write doesn't work then show us the code. If you're incapable of posting some code on a web site then programming is probably not for you. I won't waste any more time on this until you show that you're at least capable of making an attempt because if you can't even do that then helping is just a further waste of time.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  23. #23

    Thread Starter
    Member
    Join Date
    Mar 2018
    Posts
    48

    Re: Cannot connect to database

    I know how to connect database but i have an issue with this one i have posted the dbconnection code the erros that i get with image, i think these 4 connstring must be the problem, 4th of them must be connected,

  24. #24
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,675

    Re: Cannot connect to database

    Quote Originally Posted by ali3nn View Post
    I know how to connect database
    I've seen no evidence of that so far.
    Quote Originally Posted by ali3nn View Post
    i have posted the dbconnection code
    No you haven't. You've been asked to over and over but you haven't done so. The fact that you haven't and think you have is evidence that you DON'T know how to connect to a database.
    Quote Originally Posted by ali3nn View Post
    i think these 4 connstring must be the problem, 4th of them must be connected,
    And yet you haven't even bothered to post the actual connection strings. You have, again, been asked over and over to do so but you refuse to. The code that builds the connection strings is not the connection strings. It's an easy task to run the code, get the values and post them here but you refuse to do so. You ask for help and you refuse to provide the information that we have asked for repeatedly in order to do so. You've wasted far too much of everyone's time already. I won't be making any effort to help you any further here or in any future threads.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width