|
-
Sep 29th, 2018, 08:17 AM
#1
Thread Starter
Lively Member
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"];
}
}
-
Sep 29th, 2018, 08:18 AM
#2
Thread Starter
Lively Member
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.
-
Sep 29th, 2018, 10:43 AM
#3
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.
-
Sep 29th, 2018, 04:46 PM
#4
Thread Starter
Lively Member
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.
-
Sep 29th, 2018, 06:12 PM
#5
Re: Cannot connect to database
 Originally Posted by ali3nn
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.
 Originally Posted by ali3nn
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.
 Originally Posted by ali3nn
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.
-
Sep 29th, 2018, 07:03 PM
#6
Thread Starter
Lively Member
-
Sep 30th, 2018, 01:28 AM
#7
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?
-
Oct 1st, 2018, 07:37 AM
#8
Thread Starter
Lively Member
Re: Cannot connect to database
I have posted the source code of DatabaseLink.cs ?
-
Oct 1st, 2018, 07:43 AM
#9
Thread Starter
Lively Member
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?
-
Oct 1st, 2018, 07:48 AM
#10
Re: Cannot connect to database
 Originally Posted by ali3nn
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.
-
Oct 1st, 2018, 07:53 AM
#11
Thread Starter
Lively Member
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>
-
Oct 1st, 2018, 08:01 AM
#12
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.
-
Oct 1st, 2018, 08:08 AM
#13
Thread Starter
Lively Member
Re: Cannot connect to database
I think this source uses connection with settings here is an pic ?
-
Oct 1st, 2018, 08:09 AM
#14
Thread Starter
Lively Member
Re: Cannot connect to database
I think this source uses connection with settings here is an pic ?
-
Oct 1st, 2018, 08:18 AM
#15
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.
-
Oct 1st, 2018, 08:24 AM
#16
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.
-
Oct 1st, 2018, 11:14 AM
#17
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
-
Oct 1st, 2018, 07:33 PM
#18
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.
-
Oct 1st, 2018, 09:05 PM
#19
Re: Cannot connect to database
hmmmmm.... true... that means there's even more code slinging going on than I thought.... bleh...
-tg
-
Oct 1st, 2018, 09:15 PM
#20
Re: Cannot connect to database
Actually, looking back at post #6, it does say:
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.
-
Oct 2nd, 2018, 11:22 AM
#21
Thread Starter
Lively Member
Re: Cannot connect to database
I think these 3 connection strings are these that i posted ?? i have to configure all of them ?
-
Oct 2nd, 2018, 06:05 PM
#22
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.
-
Oct 4th, 2018, 07:13 PM
#23
Thread Starter
Lively Member
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,
-
Oct 4th, 2018, 08:23 PM
#24
Re: Cannot connect to database
 Originally Posted by ali3nn
I know how to connect database
I've seen no evidence of that so far.
 Originally Posted by ali3nn
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.
 Originally Posted by ali3nn
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.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|