Missing Server and User in Credentials - c#

I'm currently working with VS'13 for making c# metro forms and mysql workbench for database. The problem occurring is that it shows the error of
Missing Server and User in Credentials.
Host 'WAJiHA' is not allowed to connect to this MySQL server
(as you can see in the picture as well).
DataAccess file has following settings
"Server=localhost;Database=sbhd_v13;Uid=root;password=test123";
The database is connected with the project and executes query but doesnot allows to access the connection to the current project or any other project.
It was working good last night idk which configurations i had edited by mistake which is causing such error.
Kindly help me! I'm unable to find the right solution for this problementer image description here

Change your posted connection string to be like
string myConnectionString = "server=127.0.0.1;uid=root;pwd=test123;database=sbhd_v13;";

Related

Could not create database using package manager console in .NET 7.0

Im learning .net now and following along the course,my goal is to create CRUD app so i need a database to work with it, i have succesfuly created initial migration but database-update doesnot work
(provider: SNI_PN11, error: 50 - Local Database Runtime error
occurred. Cannot create an automatic instance. See the Windows
Application event log for error details.
im getting this error if connection strings look like this
"ConnectionStrings": {
"QuotesAppContext": "Server=(localdb)\\mssqllocaldb;Database=QuotesAppContext-811c920d-aeb7-4d04-8ba6-5c9a48d8b492;Trusted_Connection=True;MultipleActiveResultSets=true"
}
i have installed both sql server and sql management on windows 11 without problem
and if i change connection string to this
"ConnectionStrings": {
"QuotesAppContext": "Server=(localdb)\mssqllocaldb;Database=QuotesAppContext-811c920d-aeb7-4d04-8ba6-5c9a48d8b492;Trusted_Connection=True;MultipleActiveResultSets=true"
}
deleting \ problem now is
Unable to create an object of type 'QuotesAppContext'.
so it seems like an endless circle to me, thanks you for your help
write database-update and get database instance working
I find the answer which have worked for me,find this folder in regedit
"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Microsoft SQL Server\UserInstances"
and delete everything inside of it,and after that run Update-Database command again everything should work fine
P.S
i have tried reinstalling sql server,adding ports, but this solution worked for me

Connection error when configuring MySQL data source in Configure Data Source wizard

I'm currently using VS2015 and a local instance of MySQL Server (managed through Workbench) to develop a school project.
The project is a Web form app (.NET/C#) which I have never really done before. I have done C# with a MySQL connection in the past but I think it was just a Windows form app, and I had no issues connecting the database to the form.
I'm currently trying to use a GridView element from the toolbox in Visual Studio to connect to my database. When I go in and edit the source settings, I can create a connection and it will see the tables in my database.
I can then click the "Test Connection" button and it will succeed in connecting. However, if I go forward and try to select items to view from the table, and then click "Test Query" I get the following error:
I have Googled the error and tried some of the solutions found on SO like installing the Clear MEF Cache extension, but it didn't solve anything.
Additionally, I've created some functions from scratch to connect and insert data. They also have problems in that trying to insert any more than one value into the table will fail. Like INSERT INTO user_info(user_id, user_name) VALUES ('5', "Bob") will insert the user_id but not the user_name.
Please see here for a tutorial to connect to MySQL and here for filling your DataGridView from MySQL. Make sure you have the correct reference added to your project as well (References > MySQL.Data).

Developing with Azure Mobile Services in a local computer[.Net backend]

I'm developing a cloud service using Azure Mobile Services, and in order to test it quickly and debug it, I want to deploy it in my local computer. I select the project, hit F5, got it running in IIS express in my local PC. I execute the cliente against my local URI address of the IIS service and when I try to insert a value, this exception appears if I try to retrieve or insert a new object:
An exception of type 'System.ArgumentException' occurred in EntityFramework.SqlServer.dll but was not handled in user code
Additional information: The database name 'TR_MyTrip_Server_ExtraData_Service]_Persons_InsertUpdateDelete' is invalid. Database names must be of the form [<schema_name>.]<object_name>.
I debugged the Initialization of the controller and found out that mobile services deploys a LocalDb instance with this connection info on the DataBase property of the ServiceContext object:
Data Source=(localdb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-MyTrip.Server.ExtraData.Service-20140731060708.mdf;Initial Catalog=aspnet-TestProject.Server.ExtraData.Service-20140731060708;Integrated Security=True;MultipleActiveResultSets=True
It is not able to find this DataBase if I try to connect with this connection string to the LocalDB via the SQL Management Studio
I'm able to access to the LocalDb instance with the SQL management studio running this command on CMD and retrieving the Connection for the LocalDB
SqlLocalDB.exe info v11.0
Eitherway, on the SQL Management Studio I'm not able to see any DataBase relating my controller of the Mobile Services. I searched on google and the only related link I found was this but is not working... Does anybody know what's happening?
Thank you so much
This is a problem when you have a project name with periods in it. Like TestProject.Server.ExtraData.Service.
To fix this, go into the web.config and edit the appsetting named "MS_MobileServiceName" taking out the periods. This is the value used as the SQL schema name for your mobile service tables in the database. It can't have periods or other special characters in it.
I generally try to make this the same as the name of the mobile service I'll deploy to, but it's not technically required.
For whatever reason, I couldn't get this working using the accepted answer. I assume this has something to do with the disclaimer in web.config which states:
After publishing to Mobile Services, these settings will be overridden by the values specified in the portal.
However, I did find another work around in the MobileServiceContext file where I replaced this line:
string schema = ServiceSettingsDictionary.GetSchemaName();
if (!string.IsNullOrEmpty(schema))
{
modelBuilder.HasDefaultSchema(schema);
}
with a simple string value modelBuilder.HasDefaultSchema('mySchema');
I imagine there's a way to influence the output of GetSchemaName() but, considering how much effort it took to resolve this problem, I am perfectly content with this solution for now.
If you've changed the MS_MobileServiceName in config to remove the periods, and you're still getting the error, you'll need to re-run the scaffolding for the Initial migration in the package manager console:
Add-Migration Initial -Force
From what I could see, the scaffolding generates an embedded .resx that still has your old schema name (DefaultSchema), and a snapshot (Target) that is referenced in the designer code. Just changing the DefaultSchema didn't solve the issue for me, but re-running the scaffolding did.
I also added Table annotations to my models, but I don't think that was the issue. And probably isn't ideal if your service is already live.

Using a SQL Server Database File from a Class Library in C#

So I have a basic 3-tier application:
Data Access
Business Logic
Presentation
My Data Access layer is a class library, and I'm using Entity Framework and a SQL Server Database File
Say my solution is structured as such
MySolution
\MySolution.Data
\MySolution.Data\App_Data\MySolutionDB.mdf
\MySolution.BusinessLogic
\Presentation
The problem I am trying to solve is that I need to get a folder relative path to the database for the connection string because this project will not always be deployed in into the same folder structure, therefore it is imperative that the connection string is created dynamically based on the relative path.
Could someone offer some assistance on this. please?
P.S. I tried this, but it's not working:
string.Format("Data Source=(LocalDB)\v11.0;AttachDbFilename={0}\\MySolutionDB.mdf;Integrated Security=True", AppDomain.CurrentDomain.GetData("DataDirectory"))
EDIT: Getting this error message, which may be unrelated to the issue...
Connection to the database failed. The connection string is configured
with an invalid LocalDB server name. This may have been set in
'global.asax' by a pre-release version of MVC4. The default connection
factory is now set in web.config so the line in 'global.asax' starting
with 'Database.DefaultConnectionFactory = 'should be removed. See
http://go.microsoft.com/fwlink/?LinkId=243166 for details
Thanks to wdosanjos for pointing out my stupid mistake.
string.Format("Data Source=(LocalDB)\v11.0;AttachDbFilename={0}\\MySolutionDB.mdf;Integrated Security=True", AppDomain.CurrentDomain.GetData("DataDirectory"))
I did not escape \v11.0; it should have been \\v11.0;

Restore a Database Programatically (SQL Server)

I recently found this link which shows a great example of backing up and restoring a sql server database. However, my SQL Server only uses WindowsAuthentication and so it does not really require a UserName and Password. To be able to do this, I turned the line srvConn.LoginSecure = false; into srvConn.LoginSecure = true;
I was expecting to connect succesfully to the Server. However, this example returns an exception saying that it was unable to connect to the server.
Can anybody help me please? I have to learn this application for me to be able to apply the same concept to a project i'm working on. Thank you very much.
First of all if you want to enable remote connection to your server (I'm not sure if this is what you're after), Try this: http://support.microsoft.com/kb/914277 . You will also want to make sure the mixed authentication option is enabled.

Categories

Resources